can't link nginx with ghost in docker

I am deploying a ghost server on digitalocean with port default to 2368.

docker run -d --name ghost ghost

and also I deploy a nginx server as well.

  • Why does the ping from inside docker is faster than the main OS? [closed]
  • Docker --volumes-from permissions
  • Link between two docker containers in a network
  • share images between host and child docker
  • How to configure nginx to serve static from django running in a docker container
  • Publish to random host port while using --network=host
  • docker run -d -p 80:80 -p 443:443 --name nginx --link ghost:ghost -v /home/abc/nginx/sites-enabled:/etc/nginx/sites-enabled nginx

    under the path of /home/abc/nginx/sites-enabled, I have a config file – named as ghost

    server {
      server_name mydomain; 
      access_log /var/log/nginx/; 
      location / {
          proxy_set_header X-Real-IP $remote_addr;
          proxy_set_header HOST $http_host;
          proxy_set_header X-NginX-Proxy true;
          proxy_pass http://ghost:2368;
          proxy_redirect off;

    at last

    docker restart nginx,ghost

    I can clearly the nginx and ghost container is running well, and go to the IP address of server, I can see the welcome page of nginx, which says

    If you see this page, the nginx web server is successfully installed and working. Further configuration is required.

    but go to the domain, it can’ find the server or sometimes show the nginx welcome page as well

  • How can I set parameters from docker command line to configure spring boot application?
  • Docker - copy file from container to host
  • T50 does not work with docker container
  • Is it possible to optionally use the docker COPY instruction?
  • How to access private Docker Hub repository from Kubernetes on Vagrant
  • Docker Ubuntu 16.04 LTS - use tcpdump to capture GRE packets
  • 2 Solutions collect form web for “can't link nginx with ghost in docker”

    First, Your volume mapping should be -v /home/abc/nginx/sites-enabled:/etc/nginx/conf.d, not site-enabled.

    Second, because Nginx loads DNS entries when it starts up and never updates, Nginx won’t be able to locate your ghost container after ghost restarts (and thus gets a new IP address). A quickfix is to run docker restart ghost nginx instead of docker restart nginx ghost.

    Try this pre-setup nginx proxy

    Following the instructions I run the nginx proxy:

    docker run -d -p 80:80 -v /var/run/docker.sock:/tmp/docker.sock:ro jwilder/nginx-proxy

    Then you can simply run the ghost docker something like this:

    docker run --name some-blog -d -p 80:2368 -e -v /home/ghost/someblog/:/var/lib/ghost --restart unless-stopped ghost

    I have multiple ghost containers setup like this.

    Docker will be the best open platform for developers and sysadmins to build, ship, and run distributed applications.