I have a question regarding the following instructions from https://jupyter-docker-stacks.readthedocs.io/en/latest/.
This command pulls the jupyter/datascience-notebook image tagged
6b49f3337709 from Docker Hub if it is not already present on the local
host. It then starts an ephemeral container running a Jupyter Server
and exposes the server on host port 10000.
docker run -it --rm -p 10000:8888 -v "${PWD}":/home/jovyan/work
jupyter/datascience-notebook:6b49f3337709
The command mounts the current working directory on the host ({PWD} in
the example command) as /home/jovyan/work in the container. The server
logs appear in the terminal.
Visiting http://<hostname>:10000/?token=<token> in a browser loads
JupyterLab.
What is the <hostname> supposed to be? I tried my computer's username and "jovyan" but neither worked in my browser.
Related
running containersall containers
I've recently started learning docker and after following the tutorial, I ran the following command
docker run -d -p 80:80 docker/getting-started
and open up port localhost:80 and saw the docker getting started page. However, I had to run my client's project, whose port was mapped to localhost:80 as well. On account of this, I'm unable to run my client's project on localhost:80. In addition to that, any instance I randomly open up docker and then switch to localhost:80, it redirects to docker's getting started tutorial. I want to reset this localhost:80 port so that when I run my client's project, I can map them to localhost:80. Any method to rectify the issue?
First find you container's ID using:
docker ps
Supposing it is e11d9f8bb730, you can now stop and remove the container with:
docker stop e11d9f8bb730
docker rm e11d9f8bb730
Run again your container, this time using a different port:
docker run -d -p 81:80 docker/getting-started
Now your container is running on port 81 and you will be able to run your client's App on port 80.
First search for the container to see if its open:
docker container ls
If it's not then the page is probably cached by the browser.
I found this to be especially true when using Chrome.
So, if you don't see your container then use your browsers clear cache tool.
In Chrome this is as easy as right clicking on the page and selecting inspect, then right clicking the refresh page icon and selecting hard refresh.
You can use docker to map the container port to any port you choose on your local machine. As an example, you could use your docker getting started and map the port to 8080 instead of 80 like this:
docker run -d -p 127.0.0.1:8080:80/tcp docker/getting-started
All you have to do is stop the container you just started (docker / getting-started). You can open a command prompt, then type this command:
docker container ls
You can see which containers are currently running. For example:
docker containers list
You just need to do this command for the stop container:
docker container stop *yourContainerName*
I installed docker and with tensorflow image I am unable to open in browser with jupyter notebook.
What am I missing??
command used: docker run -it -v /home/$USER_NAME/tf_files:/tf_files gcr.io/tensorflow/tensorflow
where "gcr.io/tensorflow/tensorflow" is the tensorflow image and "/home/surya" is $HOME.
in terminal
output in browser
PS: docker installation is correct as "docker run hello-world" gives required message.
You missed to bind some ports. The official documentation of tensorflow provides the exposed ports with this command:
docker run -it -p 8888:8888 -v /home/surya/tf_files:/tf_files gcr.io/tensorflow/tensorflow
where -p 8888:8888 means: link the port 8888 of my local machine with the service in the container, which is also 8888. Then you can access the service at http://localhost:8888
Why do I have to map a port?
Your container shows the following:
Copy/paste this URL into your browser when you connect for the first time,
to login with a token:
http://localhost:8888/?token=1b3ec72ff1ed67f77a09beaee1dc4b9ad4e7aee26401b6f0
which means that you have to connect to the running process inside the container with the port 8888. To make the port of the container accessible from your local machine, you have to add -p 8888:8888 to your command. Then accessing the URL given to you from your container makes it possible to access the container's notebook via your local browser.
I am running the cloudera docker quickstart image (on windows) as explained on the this page.
I run it using:
docker run --hostname=quickstart.cloudera --privileged=true -t -i -p 7180:7180 -p 9080:9080 cloudera/quickstart:latest
It runs fine, I am able to run cloudera manager and access it using the url http://192.168.99.100:7180. So far so good. I also use tomcat with a simple app on localhost:9080 inside this same container. How do I access it on my host? I tried using http://192.168.99.100:9080 but it does not work.
Update: I fixed it by using the vm ip i.e. 192.168.99.100 instead of localhost for the server. Now it works. Thanks.
I have created a docker container and have installed the mailpile open source email client.
Running the mailpile binary inside the container prints the following message to STDOUT.
The Web interface address is: http://localhost:33411/
So I opened firefox on the host machine and tried 127.0.0.1:33411. It did not work.
Then I looked up the IP address assigned to the container by docker.
I looked it up by running the following command on the host,
docker inspect mp | grep IP
It said the container had an IP address of 172.17.0.3
So now, I tried 172.17.0.3:33411 on firefox running on my host. It still didn't work.
So then I stopped the container with docker stop mp. And then I committed it to an image under the name mp_image. I ran the following command on the host to do the commit.
docker commit mp mp_image
After the commit, I created a new running container, but this time forwarded port 33411 of the container to port 33411 of the host. I ran the following command on host,
docker run -i -t -p 33411:33411 --name "mailpile" mp_image /bin/bash
And now, once I got inside the container, ran the mailpile binary again and tried accessing it from the host. This time I used all these variations on the host browser,
127.0.0.1:33411
172.17.0.3:33411
Again not working. Now I started doubting if the server was running in the container in the first place. So I went inside the container and did wget 127.0.0.1:33411. And I got a nice index.html file. So the server is running..
I don't know what to do at this point. Can someone please advice?
Mailpile is built to listen on port 33411 from the local host only. Install a proxy or tunnel a connection as described here: https://github.com/mailpile/Mailpile/wiki/Accessing-The-GUI-Over-Internet
I have a ubuntu machine which is a VM where I have installed docker in it. I am using this machine from my local windows machine and doing ssh , opening the terminal to the ubuntu machine.
Now , I am going to take a docker image which contains all the necessary softwares for eg: apache installed in it. Later I am going to deploy a sample appication(which is a web applicationP on to it and save it .
Now , I am in a confused mode as in how to check the deployed application if its running properly. i.e., what would be the address of the container which containds the deployed application.
for eg:- If I type http://127.x.x.x which is the address of the ubuntu machine , I am just getting time out .
Can anyone tell me how to verify the deployed application . Also, the printing the output of the program on the console works seemlessly fine , as the output gets printed , only thing I have some doubts is regarding the web application.
There are some possibilities to check whether your app is running.
Remote API
As JimiDini said, one possibility is the Docker remote API. You can use it to see all running containers (which would be your use case, right?), inspect a certain container or start and stop containers. The API is a REST-API with several binding for programming languages (at https://docs.docker.io/reference/api/remote_api_client_libraries/). Some of them are very outdated. To use the Docker remote API from another machine, I needed to open it explicitly:
docker -H tcp://0.0.0.0:4243 -H unix:///var/run/docker.sock -d &
Note that the API is open to the world now! In a real scenario you would need to secure it in some way (e.g. see the example at http://java.dzone.com/articles/securing-docker%E2%80%99s-remote-api).
Docker PS
To see all running containers run docker ps on your host. This will list all running containers. If you do not see your app, it is not running. It also shows you the ports your app is exposing. You can also do this via the remote API.
Logs
You can also check the logs. You can run docker attach <container id> to attach to a certain container an see its stdout. You can run also run docker logs <container id> to receive the Docker logs. What I prefer is to write the logs to a certain directory, e.g. all logs to /var/log and mount this folder to my host machine. Then all your logs will end up in /home/ubuntu/docker-logs on your host.
docker run -p 80:8080 -v /home/ubuntu/docker-logs:/var/log:rw my/application
One word to ports and IP
Every container will get its own IP address. You can check this IP address via the remote API or via Docker on the host machine directly. You can also specify a certain host name for the container (by passing the --hostname="test42" to the run command). However, you mostly did not need that.
To access the application in the container, you need to open the port in the container and bind to a port on the host.
In your Dockerfile you need to EXPOSE the port your app runs on:
FROM ubuntu
...
EXPOSE 8080
CMD run-my-app.sh
When you start your container, you need to bind this port to a port of the host:
docker run -p 80:8080 my/application
Now you can access your app on http://localhost:80 or http://127.0.0.1:80.
If you app does not response, check if the container is running by typing docker ps or the remote API. If it is not running, check the logs for the reason.
(Note: If you run your Ubuntu VM in something like VirtualBox and you try to access it from your Windows machine, make sure you opened the ports in VirtualBox too!).
Docker container has a separate IP address. By default it is private (accessible only from the host-machine).
Docker provides all metadata (including IP address) via its API:
https://docs.docker.io/reference/api/docker_remote_api_v1.10/#inspect-a-container
https://docs.docker.io/reference/api/docker_remote_api_v1.10/#monitor-docker-s-events
You can also take a look at a little tool called docker-gen for inspiration. It monitors docker-events and created configuration-files on host machine using templates.
To obtain the ip address of a docker container, if you know its id (a long hex string) or if you named it:
docker inspect --format '{{ .NetworkSettings.IPAddress }}' <container-id-or-name>
Docker is running its own network and to get information about it you can run the following commands:
docker network ls
docker network inspect <network name>
docker inspect <container id>
In the output, you should be able to find the IP.
But there is also a couple of things you need to be aware of, regarding Dockerfile and docker run command:
when you EXPOSE a port in Dockerfile, the service in the container is not accessible from outside Docker, but from inside other Docker containers
and when you EXPOSE and use docker run -p ... flag, the service in the container is accessible from anywhere, even outside Docker
So for example, if your apache is running on port 8080 you should expose it in Dockerfile and then you can run it as:
docker run -d -p 8080:8080 <image name> and you should be able to access it from your host on HTTP://localhost:8080.
It is an old question/answer but it might help somebody else ;)
working as of 2020
docker inspect -f '{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}' container_name_or_id