run in the terminal:
curl -fsSL htpps://get.docker.com/ | shIt will download the latest version (not recommended for deployment in your server, you should stay on a stable version)
Check the version
docker --versionrun in the terminal:
docker run hello-worldIf it's the first time running the hello-world docker will pull the image from docker hub
after it's ready it should print
Hello from Docker.
- To check the images just run
dock images- To check running containers run
docker ps- To check all containers run
docker ps -a- to run an interactive terminal of a container
docker run -ti yourimagename- to run the container in the background
docker run -d yourimagename- choose the version of image
docker run yourimagename:version- exiting the container
Press ctrl + d or ctrl + c
- exit the container, but keep it running
press ctrl+p+q
- enter in a running container
docker attach containerID- create container without executing it
docker create imagename- stopping a container
docker stop containerID- pausing container
docker pause containerID- unpausing container
docker unpause containerID- container stats
docker stats containerID- container processes
docker top containerID- container logs
docker logs containerID- remove container
docker rm containerID- to check mem info
docker inspect containerID | grep -i memmemory: 0 means no limit
- limit memory during container creation
docker run -ti --memory 512m --name containerName ImageNamethis will create a container with 512 MB of memory limit, with the name containerName, of the image ImageName
- update the memory limit
docker update --memory 1024m containerIDnow the container can use up to 1024 MB of the ram
- check cpu info
docker inspect containerID | grep -i cpu
- creating container with limited cpu
docker run -ti --cpu-shares 1024 --name conainerName ImageNamethis container will have 1024 shares of processing power, and the processing power will be split accordingly with all shares of all container running
- updating container cpu limit
docker update --cpu-shares 1024m containerID
- create a container with external volume
docker run -ti -v /volumeName ImageName command- Running a react app inside a container
FROM node
RUN mkdir /usr/src/app
COPY . /usr/src/app
WORKDIR /usr/src/app
ENV PATH /usr/src/app/node_modules/.bin:$PATH
RUN yarn
CMD [ "npm", "start" ]- build image
docker build -t imageName:version .