Unable to run nginx inside docker - docker

I am trying to run an nginx image inside a Docker container. I have tried these steps
ssh inside ubuntu docker image docker run -v /var/run/docker.sock:/var/run/docker.sock -it ubuntu:latest bash
Installed Docker
Run Nginx image docker run -d -p 80:80 nginx
curl localhost:80 gives Connection refused

Mapping docker.sock to containers means you will be using the docker daemon of the host machine, not the container's.
So when you run docker run -d -p 80:80 nginx command, the nginx container is created and run in host machine (sibling of the ubuntu container). Hence, 80:80 maps in the host machine.
Validate this by running docker ps in ubuntu container and in the host machine. The result should match. And I guess, you can do curl localhost in the host machine and hit the nginx server as well.

Related

How to configure port when create copy of Docker container

I have Docker container cont1 on remote server, and I can connect to Jupyter notebook on it with ssh.
I try to make "copy" of that container with:
docker commit imagename
docker run -d --name cont2 -p 0.0.0.0:9999:9999/tcp imagename
I can connect to port 9999 with ssh, but I cant open Jupyter in browser.
Docker ps shows:
name PORTS
cont1 0.0.0.0:8888:8888->8888/tcp
cont2 8888/tcp, 0.0.0.0:9999->9999/tcp
I think problem is that cont2 has 2 port settings. How can I run second container correctly?
According to ps -ef | grep python, jupyter is running on cont2
Jupyter runs on 8888 port by default, so run should be like
docker run -d --name cont2 -p 0.0.0.0:9999:8888/tcp imagename

Can we run docker inside a docker container which is running in a virtual-box of Ubuntu 18.04?

I want to run docker inside another docker container. My main container is running in a virtualbox of OS Ubuntu 18.04 which is there on my Windows 10. On trying to run it, it is showing me as:
Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running?
How can I resolve this issue?
Yes, you can do this. Check for dind (docker in docker) on docker webpage how to achieve it: https://hub.docker.com/_/docker
Your error indicates that either dockerd in the top level container is not running or you didn't mount docker.sock on the dependent container to communicate with dockerd running on your top-level container.
I am running electric-flow in a docker container in my Ubuntu virtual-box using this docker command: docker run --name efserver --hostname=efserver -d -p 8080:8080 -p 9990:9990 -p 7800:7800 -p 7070:80 -p 443:443 -p 8443:8443 -p 8200:8200 -i -t ecdocker/eflow-ce. Inside this docker container, I want to install and run docker so that my CI/CD pipeline in electric-flow can access and use docker commands.
From your above description, ecdocker/eflow-ce is your CI/CD solution container, and you just want to use docker command in this container, then you did not need dind solution. You can just access to a container's host docker server.
Something like follows:
docker run --privileged --name efserver --hostname=efserver -d -p 8080:8080 -p 9990:9990 -p 7800:7800 -p 7070:80 -p 443:443 -p 8443:8443 -p 8200:8200 -v $(which docker):/usr/bin/docker -v /var/run/docker.sock:/var/run/docker.sock -i -t ecdocker/eflow-ce
Compared to your old command:
Add --privileged
Add -v $(which docker):/usr/bin/docker, then you can use docker client in container.
Add -v /var/run/docker.sock:/var/run/docker.sock, then you can access host's docker daemon using client in container.

how to config autostart service[nginx] in a running docker container

my docker install my windows10 PC . the below step is which I created the container from the powershell window.
docker run -p 80 --name web -i -t ubuntu /bin/bash
#>apt-get update
#>apt-get install -y nginx
now, I found there are 2 questions when my pc restart.
the container 'web' is not running
when start 'web' container , the 'nginx' service is not running
the first question is resolved:
docker update --restart=always web
but the second question how to do? please help me
The best option in your case is running dedicated container for nginx instead of generic ubuntu with nginx being installed each time.
Use following command to run Nginx alpine release:
docker run -p 80 --name web-Nginx -d --restart always nginx:1.15.8-alpine

Can't access docker container in browser on redhat

I am trying to run docker container on Redhat. What I did as:
download nginx: docker pull nginx
created html file at home/username/index.html and wrote "Welcome. I am Nginx server locked inside Docker"
ran the command: docker run --name my-nginx-c2 -p 8080:80 -v /home/username/html/:/usr/share/nginx/html:ro -d nginx
ran: curl http://my-ip-address:8080 and can see the output "Welcome. I am Nginx server locked inside Docker"
now the problem is when I try to see it on browser that is http://my-ip-address:8080, it doesn't work.

Apache website not updating after restarting docker

I have created an apache2 docker container
docker run -dit --name tecmint-web -p 8080:80 -v /home/user/website/:/usr/local/apache2/htdocs/ httpd:2.4
This is working. but if I stop this container and start again by docker restart <container-id>. It does not pick new html file from my /home/user/website/.
How can I realign these 2 directories after restarting docker?

Resources