Hello
Steps for docker Check Docker version: docker --version
Check Docker system information: docker info
List all Docker images on the local system: docker images
Search for an image in Docker Hub: docker search <image_name>
Pull an image from Docker Hub: docker pull <image_name>
Build an image from a Dockerfile: docker build -t <image_name>: .
Tag an image (for versioning or renaming): docker tag <image_id> <repository_name>:
Remove an image: docker rmi <image_name>
List all running containers: docker ps
List all containers (including stopped ones): docker ps -a
Run a container from an image: docker run -d -p <host_port>:<container_port> <image_name>
Run a container in interactive mode: docker run -it <image_name> /bin/bash
Stop a running container: docker stop <container_id>
Start a stopped container: docker start <container_id>
Restart a running container: docker restart <container_id>
Remove a stopped container: docker rm <container_id>
Remove all stopped containers: docker container prune
View container logs: docker logs <container_id>
Execute a command inside a running container: docker exec -it <container_id>
Copy files from container to host: docker cp <container_id>:/path_in_container /path_on_host
Copy files from host to container: docker cp /path_on_host <container_id>:/path_in_container
View the container's stats (resource usage): docker stats
Display Docker container processes (similar to top command): docker top <container_id>
List Docker volumes: docker volume ls
Remove a Docker volume: docker volume rm <volume_name>
Run a container and remove it once it's stopped: docker run --rm <image_name>
View network details of Docker: docker network ls
Create a Docker network: docker network create <netwo
************* to create docker web application
Dockerfile code =>
FROM node:14-alpine
WORKDIR /app
COPY package*.json ./
RUN npm install
COPY . .
EXPOSE 3000
CMD ["node", "app.js"]
- app.js const express = require('express'); const app = express();
app.get('/', (req, res) => { res.send('Hello, Docker!'); });
app.get('/hello', (req, res) => { res.send('Hello, World!'); });
app.get('/docker', (req, res) => { res.send('This is a Dockerized Express.js application!'); });
app.listen(3000, () => {
console.log(App running on port 4000);
});
-
execute the file by , docker build -t ( image name to set) .=> run in the folder of the js file ( dont forgt to use dot
-
run the docker command docker run -p 4000:3000 image name