Skip to content

Instantly share code, notes, and snippets.

@tristanlins
Last active October 6, 2015 08:51
Show Gist options
  • Save tristanlins/c98e6bf03ae751aebf51 to your computer and use it in GitHub Desktop.
Save tristanlins/c98e6bf03ae751aebf51 to your computer and use it in GitHub Desktop.
Using docker nginx as local server
# @file /etc/systemd/system/docker-nginx.service
# @see https://docs.docker.com/articles/host_integration/
[Unit]
Description=nginx container
Requires=docker.service
After=docker.service
[Service]
Restart=always
ExecStart=/usr/bin/docker start -a nginx
ExecStop=/usr/bin/docker stop -t 60 nginx
[Install]
WantedBy=local.target
# start container
sudo systemctl start docker-nginx
# stop container
sudo systemctl stop docker-nginx
# attach shell to container
docker exec -it nginx bash
# see the logs
docker logs nginx
# for more see
# https://hub.docker.com/_/nginx/
# https://docs.docker.com/articles/host_integration/
# create config and data directory
mkdir -p $HOME/docker/nginx/{config,data}
# initially create the docker container
docker run --restart=on-failure:5 \
--volume=$HOME/docker/nginx/config:/etc/nginx/conf.d \
--volume=$HOME/docker/nginx/data:/var/www \
--publish=80:80 \
--hostname=nginx \
--name=nginx \
--detach=true \
nginx:latest
# place your webserver vhost configuration in $HOME/docker/nginx/config
# and your web-files in $HOME/docker/nginx/data (internally used as /var/www)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment