Docker Basics
# Oct 25, 2021Docker is a containerization tool used to create images to run across different computers. It’s different from a VM because the containers share the same OS. For docker to run, Docker Desktop should be running in the background and WSL2 should be activated (Windows 10). In Windows, a process named vmmem runs in the background with WSL2 and it uses some RAM. This app is the VM in which the containers run.
We should create a Dockerfile (no extension) to tell docker how to build the image before using docker build. Or we can run by giving parameters to the docker run command.
Some Useful Commands In Docker
- docker ps [-a](Show All): Shows Processes (Containers).
- docker run [-it](interactive) [-p](publish) [port_out:port_in](Expose Port) imageName: Run A Docker Image by creating a new container.
- docker stop containerName
- docker start [–interactive] containerName: Start a stopped container.
- docker build folderName
- docker exec -it containerName /bin/bash : Used to enter inside the container machine.
- docker image ls: List Images
We can also use docker run imageName on docker hub to create a container from an image in the docker hub.
RUN vs CMD
RUN is runned while creating the image. CMD is run when the container starts.