Reputation: 2208
I have been following a blog for setting up Nginx with SSL from https://blog.harveydelaney.com/hosting-websites-using-docker-nginx/
The article refers to a docker-compose.yml
file that doesn't have a version specified at the beginning, but I assume it's at least version 2 as it does have a reference to volumes_from
setting within it. This volumes_from
is no longer supported in version 3.
Could someone please help migrate the following file to version 3? I am new to the docker / docker-compose / K8s world.
version: "3.8"
services:
proxy:
image: jwilder/nginx-proxy
container_name: nginx-proxy
ports:
- '80:80'
- '443:443'
volumes:
- /var/run/docker.sock:/tmp/docker.sock:ro
- /etc/nginx/vhost.d
- /usr/share/nginx/html
- C:\Data\DockerData\nginxSSL\certs:/etc/nginx/certs:ro
ssl-companion:
image: jrcs/letsencrypt-nginx-proxy-companion
container_name: ssl-companion
volumes:
- C:\Data\DockerData\nginxSSL\certs:/etc/nginx/certs:rw
- /var/run/docker.sock:/var/run/docker.sock:ro
volumes_from: # <-- version 3 doesn't like this
- proxy
depends_on:
- proxy
Update after answer: (for anyone looking to find answer in question)
version 3 no longer supports volumes_from
, per David's answer below there are two options:
Upvotes: 0
Views: 1999
Reputation: 263617
volumes_from
doesn't make sense in Swarm Mode since containers in Swarm Mode may be on different nodes, and therefore you cannot share bind mounts between those containers.
Why am I talking about Swarm Mode? Because that's the reason for compose version 3.x. Don't look at the version like a normal upgrade, it's the easiest way Docker had to specify what was supported in Swarm Mode, making 3.x a requirement to update the file to run in Swarm Mode. Though it's compatible to run a 3.x compose file in docker-compose
too.
If you aren't using Swarm Mode, then stick with either version 2.x of the compose file, or upgrade to the compose spec which has no version number. You'll also want to switch from docker-compose
the python command to docker compose
(with a space) which is written in Go (in newer versions of docker, you may find docker-compose
is a stub pointing to docker compose
). The compose-spec is a combination of the version 2 and version 3 syntax and different implementations use the features they understand from this spec.
As others have mentioned, volumes_from
is a relatively legacy feature. It was designed before named volumes were available in docker, and so sharing volumes between containers would involve creating a data container. If the data container was every deleted, so was your data, so workflows quickly moved away from that model (since containers are typically ephemeral).
Upvotes: 1
Reputation: 1711
Adding onto David Maze's answer, these are the relevant bits from a working docker-compose.yml
file that follows the letsencrypt-nginx-sidecar design pattern from the original question.
version: "3.8"
services:
nginx-proxy:
container_name: nginx-proxy
image: jwilder/nginx-proxy
ports:
- "80:80"
- "443:443"
volumes:
- "vhosts:/etc/nginx/vhost.d"
- "nginx:/usr/share/nginx/html"
- "certs:/etc/nginx/certs"
- "/var/run/docker.sock:/tmp/docker.sock:ro"
letsencrypt-nginx-proxy-companion:
image: jrcs/letsencrypt-nginx-proxy-companion
volumes:
- "vhosts:/etc/nginx/vhost.d"
- "nginx:/usr/share/nginx/html"
- "certs:/etc/nginx/certs"
- "/var/run/docker.sock:/var/run/docker.sock:ro"
environment:
NGINX_PROXY_CONTAINER: nginx-proxy
volumes:
vhosts:
nginx:
certs:
Note: To complete the migration to docker-compose v3, the NGINX_PROXY_CONTAINER
environment variable needs to be set on the letsencrypt-nginx-proxy-companion
container with the container_name
value from nginx-proxy
.
Upvotes: 2
Reputation: 158868
The Compose file version 3 upgrade nodes say:
volumes_from
: To share a volume between services, define it using the top-levelvolumes
option and reference it from each service that shares it using the service-levelvolumes
option.
You have to do this for each directory you want to share. For the nginx virtual hosts directory, for example:
version: '3'
volumes:
vhosts: # can be empty
services:
proxy:
volumes:
- vhosts:/etc/nginx/vhost.d
ssl-companion:
volumes:
- vhosts:/etc/nginx/vhost.d
Using the volumes_from:
option is a little unusual in general: it involves one container wanting to use every volume from another, and their filesystem layouts being compatible so that they can use the exact same paths.
(You mention Kubernetes in the question. Sharing files between Kubernetes pods is tricky, since most of the standard volume types can only be mounted in one place at a time, and generally you should try to design around needing shared volumes [even in plain Docker]. In this specific case where the two processes are very closely connected you could create an emptyDir
volume to share between two containers in a single pod, but in general that's an unusual setup.)
Upvotes: 2