Running nginx

Is it possible to spin up an nginx server through circleci? I’ve tried unsuccessfully to add docker - image: nginx to the config.yml, but this doesn’t seem to actually install nginx.

Not done it, but I’m sure it is - my Apache, custom HTTP listeners and web socket listeners all work fine inside CircleCI. Have you got NginX working locally in a Docker container, or are you wanting to use a pre-build image?

Let’s see your whole config.yml please, perhaps there’s a mistake.

Yes I have a local Docker container with nginx going. I’m in the process of trying to use apt-get install nginx, from a custom Docker file.

This is what my config looked like at earlier tries:

version: 2
jobs:
  build:
    docker:
      - image: nginx

working_directory: ~/repo

steps:
  - checkout
  - run: echo $PATH
  - run: nginx
  - run: nginx -v

Ah, gotcha. It looks like you’ve got the container name correct. Maybe it’s worth trying the fully-qualified path, rather than just nginx?

I’m able to get this running with creating a new Docker image:

FROM circleci/node:latest
USER root
RUN apt-get update && apt-get install nginx
EXPOSE 80

For whatever reason using FROM nginx in the Docker file doesn’t work. It seems like I’m pulling down more than I need here… If anyone has an alternative approach I’d love to see it.

1 Like

@halfer - you mean you can just throw in https://hub.docker.com/_/nginx/ to the config.yml file?

No, but that page is the official docs for NginX on Docker Hub, so is a good source of info (e.g. what is the base name of the container).

@halfer Thanks for the help!

No worries. It’s odd that the basic container works for you locally and not on Circle. Are you perhaps adding some custom commands or env vars to your docker run command?

Personally, I would not worry about it too much - if the new one works, that’s great. Unless the new image is much larger than you would like, just stick with it. Most of my containers are under 100M, but I have one stubborn one that only works on Ubuntu, and that’s 500M+! I’ll fix it on a rainy day… :umbrella:

Yeah, I’m not doing anything custom. I try to start things off as simple as possible. As per your advice - image: nginx:stable works fine. It seems like defining a tag might be required (or it might be possible that by excluding a tag it was defaulting to the latest tag which could have been causing errors).

OK, great. I’d not only recommend using a fixed tag, but use a version-specific tag too. For maximum reproducibility, you don’t want stable to mean something different over time. Upgrade the tag manually in a controlled fashion instead.