snippetdockerMinor
How to connect to a docker container?
Viewed 0 times
dockerconnectcontainerhow
Problem
I have the following
This is how I build my
Next, this is how I bring my container up:
Then I check my container's ip via the following command:
I would like to execute a
But for some reason, my command keeps hanging. I'm not sure why this is happening. I'm running my
Dockerfile:FROM ubuntu:latest
MAINTAINER Valter Silva
RUN apt-get update
RUN apt-get install -y apache2
ADD index.html /var/www/html/
CMD /usr/sbin/apache2ctl -D FOREGROUND
EXPOSE 22
EXPOSE 80This is how I build my
image:docker build --tags mob:latest .Next, this is how I bring my container up:
docker run -d --name website mobThen I check my container's ip via the following command:
docker network inspect bridgeI would like to execute a
curl on this ip to ensure that my website is up and running:curl 172.17.0.2But for some reason, my command keeps hanging. I'm not sure why this is happening. I'm running my
dockeron a MacOS system.Solution
You can get to know if your site is up and running in the following way,
Map both the ports of inside container to the host using -p option and try to
Scenario:-
Run your container with the following command,
Explanation:-
Now,
If your service is running properly, you will have got the response
P.S:- Make sure nothing is running in 80 and 20 on host before running the docker run command
Map both the ports of inside container to the host using -p option and try to
curl localhost:portScenario:-
Run your container with the following command,
docker run -d --name website -p 80:80 -p 22:22 mobExplanation:-
-p host_port:container's_portNow,
curl localhost:80 or localhost:22If your service is running properly, you will have got the response
P.S:- Make sure nothing is running in 80 and 20 on host before running the docker run command
Code Snippets
docker run -d --name website -p 80:80 -p 22:22 mobContext
StackExchange DevOps Q#3229, answer score: 8
Revisions (0)
No revisions yet.