I have an ubuntu:16.04 container running with docker cli installed. I'm able to run a node container inside the ubuntu container but unable to access it.
Getting the following errors
"Could not resolve host: node-server"
"Connection refused"
I was trying to access the node-container from the ubuntu container. Is there any way to link ubuntu container to node container.
DockerFile
FROM ubuntu:16.04
# Install docker-cli & curl
COPY start.sh
ENTRYPOINT ["bash", "start.sh"]
start.sh
#!/bin/bash
docker run -d -p 4020:4020 --name my-node node-service
curl http://my-node:4020
I was expecting to connect to the node-service through ubuntu container. Am I missing anything??
Related
I started to work with docker. I dockerized simple node.js app. I'm not able to access to my container from outside world (means by browser).
Stack:
node.js app with 4 endpoints (I used hapi server).
macOS
docker desktop community version 2.0.0.2
Here is my dockerfile:
FROM node:10.13-alpine
ENV NODE_ENV production
WORKDIR /usr/src/app
COPY ["package.json", "package-lock.json*", "npm-shrinkwrap.json*", "./"]
RUN npm install --production --silent && mv node_modules ../
RUN npm install -g nodemon
COPY . .
EXPOSE 8000
CMD ["npm","run", "start-server"]
I did following steps:
I run from command line from my working dir:
docker image build -t ares-maros .
docker container run -d --name rest-api -p 8000:8000 ares-maros
I checked if container is running via docker container ps
Here is the result:
- container is running
I open the browser and type 0.0.0.0:8000 (also tried with 127.0.0.1:8000 or localhost:8000)
result:
So running docker container is not rechable by browser
I also go into the container typing docker exec -it 81b3d9b17db9 sh and try to reach my node-app inside of container via wget/curl and that's works. I get responses fron all node.js endpoints.
Where could be the problem ? Maybe my mac can blocked connection ?
Thanks for help.
Please check the order of the parameters of the following command:
docker container run -d --name rest-api -p 8000:8000 ares-maros
I faced a similar. I was using -p port:port at the end of the command. Simply moving it to after 'Docker run' solved it for me.
I have two containers running on a host. When I'm in container A I want to run a diff on container B compared to it's image to see what has changed in the filesystem. I know this can be ran easily from the host itself, but I'm wondering is there any way of doing this from inside container A, to see the difference on container B?
You can run any docker commands from within container which will communicate with host docker daemon if:
You have access to docker socket inside container
You have docker client inside container
You can achieve first condition by mounting docker socket to container - add following to your docker run call:
-v /var/run/docker.sock:/var/run/docker.sock.
The second condition depends on your docker image.
If you are running bare Ubuntu image you can have shell inside container which will be able to do what you want with following command:
docker run -it -v /var/run/docker.sock:/var/run/docker.sock ubuntu:latest sh -c "apt-get update ; apt-get install docker.io -y ; bash"
I am a Docker-newbie and I've got a project from another developer including a Dockerfile. This shall give me the Virtual Machine to continue work with the (nodeJS-) project inside this project folder.
Docker is already installed on my machine.
How can I launch this container now?
I've read about a command
sudo docker run -name my_first_instance
but i can't find any container name in the Dockerfile.
The dockerfile will create an image for you that you can launch containers from. this being said , Follow this:
Create a folder.
Copy dockerfile in the folder
cd into the folder execute the following command:
docker build -t <your desired image name> .
This will create an image using directives in the dockerfile in the current folder.
Now launch a container from the image.
docker run -d --name <your container name> <imagename from previous step> <optional startup commands>
Useful docker commands:
You can expose ports in the previous command using -p switch.
You can list Images via docker images
You can list running containers via docker ps
you can list running + exited containers via docker ps -a
have a look at
https://hub.docker.com/_/node/
it is the official repository for NodeJS docker images
If you want some docker images based on NodeJS, you will need to pull them docker pull my_node_image
Then you can launch one with such a command
docker run -it --rm --name my-running-script -v "$PWD":/usr/src/app -w /usr/src/app node:4 node your-daemon-or-script.js
The Dockerfile is just the recipe to build a docker image, for Nginx, Mysql, MongoDb, Redis, Wordpress, Spotify, atop, htop...
If docker images shows nothing, it means you have not yet pulled any docker image.
I'm using Docker for a course about Spark.
I've set up my environment like this:
docker pull bigdatauniversity/spark2
docker run -it --name bdu_spark2 -P -p 4040:4040 -p 4041:4041 -p 8080:8080 -p 8081:8081 bigdatauniversity/spark2:latest /etc/bootstrap.sh -bash
Then I exited Docker and ran this:
docker start bdu_spark2
docker attach bdu_spark2
Now, when I go into Zeppelin I can't find the files given for the course.
I tried finding out if there is another Zeppelin process running at another port so I ran in the Docker console:
docker ps
However, the command docker is not recognised:
bash: docker: command not found
I also tried running docker exec -it docker ps but I got the same result.
So how can I see the files from the Docker container in Zeppelin?
I'm relatively new to Docker and have a node web server which I have added to a docker image. My image is built using packer, so I don't have a Dockerfile.
My question is when running the docker container on the command line with docker run -it -d <imageId> is there a way to pass in the command to run my web server that resides in the container?
So something like docker run -it -d <imageId> npm start
Got it working with
docker run -it -d -w /path/to/code/folder <imageName:version> node server.js 'daemon off;'