some basic commands might not run windows
docker --version
whoami
uanme
docker container ls
docker stop dockerId
docker container rm dockerId
docker container rm -f dockerId
docker image ls or docker image
docker image rm imageId
docker start containerName
docker exec -it containerName bash
docker run -it ubuntu
-it === interactive gonna interact with the ubuntu machine
docker run -d ubuntu
-d == deatached mode
docker pull node
docker run -it node
docker tag nikhil791/myapp nikhil791/rename
- make a simpel node server
npm init -y
npm i express
- make a simple express app
const express = require('express')
const app = express()
const port = 9000
app.get('/', (req, res) => {
res.json(message:'I am inside docker container')
})
app.listen(port, () => {
console.log(`Server is running on port ${port}`)
})
- In order to make a docker image make a docker file naming "Dockerfile"
FROM node:latest
COPY index.js /home/app/index.js
COPY package.json /home/app/package.json
WORKDIR /home/app
RUN npm install
EXPOSE 9000
CMD [ "node", "index" ]
docker build -t myapp . or the file location
docker run -it myapp
docker ps
but it will not work as you have exposed the 9000 port inside the docker machine and also you have exposed that port to the external world but have not mapped it to main machine
Port mapping (publishing ports) can only be done when creating a new container, not with existing containers.
docker run -p 3000:9000 myapp
- here if we don't write the EXPOSE 9000 in the Dockerfile the servers 9000 port will be still accessible because of the run -p command
docker run -it --name nx -p 8080:80 nginx
docker run -it -p 3000:9000 myapp
COPY index.js /home/app/index.js
COPY package.json /home/app/package.json
instead of this use
COPY . /home/app
it will copy all the file also the node modules to avoid this
make a .dockerignore file and add node_modules/
docker build -t username/image_name . or the file location
- it is the naming convention and every idiot should follow it
docker push username/image_name
app.run(debug=True,host="0.0.0.0", port=5000)
app.run(debug=True, port=5000)