This is my personal reference for essential Docker commands while learning containerization.
| Action | Command |
|---|---|
| Check Docker version | docker --version |
| Check system info | docker info |
| List running containers | docker ps |
| List all containers (stopped) | docker ps -a |
| List all images | docker images |
| Pull an image from Docker Hub | docker pull ubuntu |
| Run a container (interactive) | docker run -it ubuntu bash |
| Run container (detached) | docker run -d ubuntu sleep 1000 |
| Stop a running container | docker stop <container_id> |
| Remove a container | docker rm <container_id> |
| Remove an image | docker rmi <image_id> |
| View container logs | docker logs <container_id> |
| Execute command inside container | docker exec -it <container_id> bash |
docker run -it -p 3000:3000 <image_name>
node App is in the /docker-app file
docker build -t <image_name> .
docker build -t fisrt-mynode .
const express = require('express');
const app = express();
const PORT = process.env.PORT || 8000;
app.get('/', (req, res) => {
return res.json({ message: "Hello Node from container v2" });
});
app.listen(PORT, () => console.log(`Server is running on port ${PORT}`));FROM ubuntu
RUN apt-get update
RUN apt-get install -y curl
RUN curl -sL https://deb.nodesource.com/setup_18.x | bash -
RUN apt-get upgrade -y
RUN apt-get install -y nodejs
COPY package.json package.json
COPY package-lock.json package-lock.json
COPY main.js main.js
RUN npm install
ENTRYPOINT ["node", "main.js"]
docker run -it -e PORT=4000 -p 3000:3000 < image_name>
docker build -t ismaildcode/first-dockerapp .
docker pull ismaildcode/first-dockerapp:latest
simple Node app for understand how to create public image
Simply runing on PORT localhost:4000
