npm init -y
in package.json: "type": "module"
docker pull <imagename> //loads the image from the docker hub
docker run <imagename> // creates a container from an image, if the image is not available locally docker tries to load it from the hub
docker image ls // lists the existing image files
docker container ls // lists all running containers
docker container ls -a // also lists all terminated containers
docker start <containername | containerid> // start the container
docker container stop <containername > // stop the container
docker rm <containername | containerid> // remove container
1.- Create a Dockerfile
# we use the node image (with ubuntu:alpine) as basis image
FROM node:alpine
# create a folder for the project
RUN mkdir firstdocker
# go to the new folder
WORKDIR /firstdocker
# we copy all ours data in our image
COPY . .
# we create the necessary files
RUN npm i
# We give the PORT number
EXPOSE 9000
# We define the comands to start the container as Array
CMD ["node", "app.js"]
docker build .
docker image ls
docker run --name firstdocker_01 -d -p 8080:9000 1599a7e57c93
(with the id run the image in backdround (-d) and give a new port for 9000-> here 8080)
docker container ls
check the container list & test the container
Exercise: Create 1 img & 3 container from the same image with dif. Ports and stop it and delete one container. Start the remaining containers again
All the process:
docker build .
docker image ls
docker run --name firstdocker_1 -d -p 8081:9000 c98ca0ab7f53
docker run --name firstdocker_2 -d -p 8082:9000 c98ca0ab7f53
docker run --name firstdocker_3 -d -p 8083:9000 c98ca0ab7f53
docker container ls
docker container stop firstdocker_2 firstdocker_3
docker container ls -a
docker rm firstdocker_3
docker container ls -a