Docker Community Forums

Share and learn in the Docker community.

Need Clarification on docker hub

build
docker
dockerhub

(Telednacomm) #1

I want to create a image for my nodejs app. I have a total code which is running on CentOS. I created a account in docker and uploaded the image using below statements.

docker build -t my-nodejs-app . docker tag telednacomm/my-nodejs-app:latest telednacomm/node:ravi docker push telednacomm/node:ravi

Later in another server I am using
docker pull telednacomm/node:ravi

Here its not running as I expected.

Here is my Dockerfile

FROM node:6-onbuild
# Set in what directory commands will run
WORKDIR /home/app
# Put all our code inside that directory that lives in the container
ADD . /home/app
# Install dependencies
RUN \
mkdir -p /home/app && \
mkdir -p /home/Node && \
cd /home/Node && \
wget https://nodejs.org/dist/v6.2.2/node-v6.2.2-linux-x64.tar.gz && \
tar -zxvf node-v6.2.2-linux-x64.tar.gz && \
cd /usr/bin && \
ln -s /home/Node/node-v6.2.2-linux-x64/bin/node node && \
ln -s /home/Node/node-v6.2.2-linux-x64/bin/npm npm
# replace this with your application's default port
EXPOSE 3000
# The command to run our app when the container is run
CMD ["node", "app.js"]

Is this the right way to mention the Dockerfile??? After pulling the image I expected my code in /home/app. But I am not getting the code. How its actually works??? What am i missing???


(Czechjiri) #2

not sure what exactly you asking… I can see code

docker run -d telednacomm/node:ravi
e6b778e60159cb30598b8365d5594b7e2ed3040a6502551cd963764d6664e649

docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
e6b778e60159 telednacomm/node:ravi “node app.js” 5 seconds ago Up 4 seconds 3000/tcp amazing_golick

docker logs amazing_golick
Elasticsearch INFO: 2016-07-22T17:57:36Z
Adding connection to http://172.16.15.153:9200/

Elasticsearch INFO: 2016-07-22T17:57:36Z
Adding connection to http://172.16.5.115:9200/

info: Express server started listening on port 3010

docker exec -it amazing_golick ls -l
total 52
-rw-r–r-- 1 root root 659 Jul 22 12:04 Dockerfile
-rw-r–r-- 1 root root 338 Jul 1 12:57 README.md
-rw-r–r-- 1 root root 1313 Jul 20 07:58 app.js
drwxr-xr-x 2 root root 4096 Jul 21 11:46 config
-rw-r–r-- 1 root root 3 Jul 22 04:51 default-0.json
drwxr-xr-x 2 root root 4096 Jul 11 08:45 inputfile
drwxr-xr-x 2 root root 4096 Jul 22 17:57 logs
drwxr-xr-x 3 root root 4096 Jul 18 10:29 modules
drwxr-xr-x 131 root root 4096 Jul 21 11:31 node_modules
-rw-r–r-- 1 root root 367 Jul 22 04:55 package.json
drwxr-xr-x 3 root root 4096 Jul 1 12:57 public
drwxr-xr-x 2 root root 4096 Jul 18 06:48 routes
drwxr-xr-x 2 root root 4096 Jul 18 06:48 views


(Telednacomm) #3

At first its not listening on the port 3000. But working normally when I run it maually (node app.js)

And also what I expected is totally different.

What I expected is

The Run whats to create a /home/app directory and copy all the code files into it. And create this /home/Node directory and download nodeJS binaries to install node & later I have to run my image. But these directories are not creating in my server when I pull the image.

After pulling the image if I want to edit the code where can I edit the files.

Suppose package.json

# Put all our code inside that directory that lives in the container ADD . /home/app

I expected all the files (whatever you are seeing in docker exec -it amazing_golick ls -l) in the directory to edit. But the folder is not created when I pull the image.


(Czechjiri) #4

docker exec -it infallible_lamport sh

# pwd
/home/app
# cd ..
# ls -l
total 8
drwxr-xr-x  3 root root 4096 Jul 22 12:05 Node
drwxr-xr-x 12 root root 4096 Jul 26 22:55 app

docker run -p 3000:3000 -d telednacomm/node:ravi
curl localhost:3000
"Ok"

it seems whatever you started is running


(Telednacomm) #5

Thanks very much for your answer. Its working now. but small question

Why this flag ??? Is it needed ??? I already mentioned my port in the nodeJS code & also in docker file. Again what this flag will do here???


(Czechjiri) #6

there are many articles out there explaining differences between EXPOSE and PUBLISH

for example https://www.ctl.io/developers/blog/post/docker-networking-rules/