Home > Software design >  Docker: How to use a Dockerfile in addition to docker-compose.yml
Docker: How to use a Dockerfile in addition to docker-compose.yml

Time:10-26

I am using this repo to set up a local wordpress development environment: https://github.com/mjstealey/wordpress-nginx-docker#tldr

I hijacked the docker-compose to change the nginx port, but also to try to install openssl and vim on the nginx server. But when I do a docker-compose up the nginx server never starts properly.

This is what i see:

CONTAINER ID   IMAGE                  COMMAND                  CREATED              STATUS                          PORTS                    NAMES
57cf3dff059f   nginx:latest           "bash"                   About a minute ago   Restarting (0) 14 seconds ago                            nginx

I tried to reference a Dockerfile inside the docker-compose like this:

  nginx:
    image: nginx:${NGINX_VERSION:-latest}
    container_name: nginx
    ports:
      - '8085:8085'
      - '443:443'
    build: .
    volumes:
      - ${NGINX_CONF_DIR:-./nginx}:/etc/nginx/conf.d
      - ${NGINX_LOG_DIR:-./logs/nginx}:/var/log/nginx
      - ${WORDPRESS_DATA_DIR:-./wordpress}:/var/www/html
      - ${SSL_CERTS_DIR:-./certs}:/etc/letsencrypt
      - ${SSL_CERTS_DATA_DIR:-./certs-data}:/data/letsencrypt
    depends_on:
      - wordpress
    restart: always

Notice the line that says "build: .". Here's the contents of my Dockerfile:

FROM debian:buster-slim
RUN apt-get update

# installing vim isn't necessary.  but just handy.
RUN apt-get -y install openssl
RUN apt-get -y install vim

Clearly, I'm doing something wrong. Maybe I should be defining tasks directly in the docker-compose for the nginx server? I wanted to find a way to make a clean separation between our customizations and the original code. But maybe this isn't possible.

Thanks

EDIT 1

This is what the Dockerfile looks like:

FROM nginx:latest
RUN apt-get update
  && apt-get -y install openssl
  && apt-get -y install vim

And the nginx section of the docker-compose.yml:

  nginx:
    #image: nginx:${NGINX_VERSION:-latest}
    container_name: nginx
    ports:
      - '8085:8085'
      - '443:443'
    build: .
    volumes:
      - ${NGINX_CONF_DIR:-./nginx}:/etc/nginx/conf.d
      - ${NGINX_LOG_DIR:-./logs/nginx}:/var/log/nginx
      - ${WORDPRESS_DATA_DIR:-./wordpress}:/var/www/html
      - ${SSL_CERTS_DIR:-./certs}:/etc/letsencrypt
      - ${SSL_CERTS_DATA_DIR:-./certs-data}:/data/letsencrypt
    depends_on:
      - wordpress
    restart: always

CodePudding user response:

I think you maybe need to change the base image that you are using in the docker file?:

FROM nginx:latest

Then in the docker file, because you are creating your own customised version of nginx image, you should either give custom name or tag.

  • Related