Docker Community Forums

Share and learn in the Docker community.

How to start an nginx container automatically?

docker

(Zoemak) #1

Hi all,I’ve try to build and start an nginx container which start automatically when windows log on.
but it desn’t work.
here is my docker-compose.xml

version: "2"
services:
nginx1:
image: nginx:1.10.1
container_name: nginx1
ports:
- 80:80
- 443:443
- 8001:8001
- 8002:8002
volumes:
- /c/Users/Dev/.nginx/nginx.conf:/etc/nginx/nginx.conf:ro
- /c/Users/Dev/.nginx/html:/etc/nginx/html:ro
- /c/Users/Dev/d:/d:ro
command: /bin/sh -c "nginx -g ‘daemon off;’"
restart: always

I’ve also tried using

docker run --restart=always

the result is same.

Is there any ways to make it work?

thanks a lot.


(Dvohra) #2

docker run --restart=always nginx
should restart a Docker container.


(Michael Friis) #3

Have you considered running this with docker service create (after running docker swarm init) - that should keep it running.