Last active
          October 6, 2015 08:51 
        
      - 
      
- 
        Save tristanlins/c98e6bf03ae751aebf51 to your computer and use it in GitHub Desktop. 
    Using docker nginx as local server
  
        
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | # @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 | 
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | # 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/ | 
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | # 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