Docker Commands


Docker Container
A set of layers of images. mostly linux base images, mostly alpine because it is a lightweight version of Linux OS.
Application image is always on top
Docker Architecture
What happens when you run the following commands;
docker pull - connects to docker daemon, check if we have the image or not and then pull the image from the registry, store it on the host
docker run - you specify the parameters and conatiner name, it will connect to docker hostc, chack if we have the image; if yes it creates a conatiner of the image, otherwise it pulls the image from the registry and store the image
Docker Commands
docker -v: check version and if installed
docker images - list of images
docker run - to run a container
docker run -d - to run a container in detachment mode
docker run- to see all the logs
docker run image_name
You have to pass some environment variables i.e. docker run -e environment_variable image_name
docker ps - list of running containers
docker stop container_id - to stop a container
docker ps -a - to see all running and non-running containers
docker start container_id - to start an already existing container.
docker stop container_id - to stop the container
docker logs conatiner_name - to see all the logs
docker logs -f container_name - to keep listening to the logs that’ll happen on that container
docker exec -it objective-keller psql -U postgres - to run some commands inside the container to see what it has, log into the container in an interactive mode
exec - execute, it - interactive objective-keller - container_name, psql - the mode you want to connect to, -U -specific for postgres, postgres - username
Inside Postgres
\l - list of all the databases
create database db_name; - to create db
\l dt - list tables
exit - to exit the interactive mode
docker run —name custom_name -e POSTGRES_PASSWORD=password postgres - to specify the container name.
docker run -d —name custom_name-detached -e… the versionpostgres - to run in detached mode, gives us a SHA or hashcode
docker rm container_id - to remove container, you can’t remove a running container
docker images - to see all the images.
PS: removing the container doesn’t remove the images
docker rmi image_id - id or image_name
docker pull redis : 6.2 - to specify
Subscribe to my newsletter
Read articles from Phenny Mwaisaka directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by