CodeBucks logo
Estevam's Blog
DevOPS

Comandos Essenciais do Docker

Comandos Essenciais do Docker
0 views
5 min read
#DevOPS

Docker CLI Cheat Sheet

Cover image for Docker CLI Cheat Sheet...

#docker #dockercompose #devops #cheatsheet

Table of content 📎


Docker Images

Pull image from Docker Hub

To pull the Docker image available in docker hub repository. Image includes all the open-source images and your custom images.

docker pull imageName
docker pull naveenv24/hello_world

To search for any image available in docker hub includes additional filter option.

docker search imageName
docker search naveenv24/hello_world

Create new image

All images which are created is dependent on the base image eg. alpine image. If we name the file as Dockerfile by default docker picks up the file to perform actions related to the image

FROM alpine:3.7   RUN apk add --no-cache mysql-client   ENTRYPOINT ["mysql"]

Build an image

**docker build . (OR) **docker build dir/pathto/
docker build -f` **Dockerfile
docker build -f Dockerfile.renamed

Pushing the image

This is used to push your new or any updated image to the docker hub. Perquisite is the docker login to the registry.

docker push` imageNameToBeUploaded
docker push naveenv24/hello_world

Removing the image

This command will help you remove the image from your environment if it’s not having any dependency. Include -f to forcefully remove. rmi implies remove-image.

docker rmi -f imageName
docker rmi naveenv24/hello_world

Docker Container

Creating a container

This command will create writable container over the specified image. This command will only create the container but will not run/start it. -t implies target -I implies the image name.

docker create  t -I ImageName --name ContainerName
docker create  t -I naveenv24/hello_world --name hw-container

Running the container

This command will create the container if not created and starts the container the -it implies interactive mode and -d implies detach mode which run the container background

docker run –name containerName -it -d imageName
docker run –name hw-container -it -d naveenv24/hello_world

Renaming the container

This command will rename you’re container name

docker rename oldContainerName newContainerName
docker rename hw-container hw-con-new

Updating the container

To update any container related configuration update command is used. Configuration more related to the CPU, memory etc. , Note: currently not available in windows at the time of this been posted.

docker run -dit –name containerName –kernel-memory 50M ubuntu bash
docker update –kernel-memory 100M containerName

Container Start, Stop and Restart

Stop the running container or start the non running container or use restart to perform both. -t wait time before killing the container.

docker stop containerName
docker stop hw-con-new
 
docker start containerName
docker start hw-con-new
 
docker restart -t containerName
docker restart -t hw-con-new

Pausing and Resuming

To suspend any process running in the container temporarily and to un-suspend the process again.

docker pause containerName
docker pause hw-con-new
 
docker unpause containerName
docker unpause hw-con-new

Removing the container

To remove the one or more container. To remove the container forcefully add -f or –force.

docker rm -v -f containerName
docker rm -v -f hw-con-new

Listed commands will provide info related to container or process running In the container.

docker ps > will show all the active running container (-a includes remaining available container)
 
docker logs hw-con-new >> gets logs from container. (You can use a custom log driver, but logs is only available for json-file and journald in 1.10).
 
docker inspect hw-con-new >> displays all the info related to container includes the ips and ports related details\
 
docker port hw-con-new\>> shows all the ports running in the container\
 
docker stats hw-con-new >> Display a live stream of container(s) resource usage statistics

Docker Networks

Creating a Network

To create a network by default will create a bridge network, to specify a network type use -d (driver) option along with the command.

docker network create -d bridge networkName
 
docker network create -d bridge mynetwork

Listing all Network

To view all the available networks in the docker

docker network ls

Inspecting a Network

To view the detailed information about the network

docker network inspect networkName
docker network inspect mynetwork

Removing

To remove the network from the available list

docker network rm networkName
docker network rm mynetwork

Connect & Disconnecting container from a network

To connect the container from the network

docker network connect networkName containerName
docker network connect mynetwork hw-con-new

To disconnect the container from the network

docker network disconnect networkName containerName
docker network disconnect mynetwork hw-con-new

These are all the command we will frequently looking into when any implementation is undergone.

Though it might seem few these are basically enough to perform and docker build with multiple services connected through.. 🚀

Appreciate spending your time on this. Hope you liked it.. Share your thoughts this might be useful for improving the quality. 🍻

GitHub Flavored Markdown

Também adicionei suporte para o GitHub Flavored Markdown usando remark-gfm.

Com remark-gfm, obtemos algumas funcionalidades extras em nosso markdown. Exemplo: literais de autolink.

Um link como www.github.com ou https://www.estevamsouza.com seria automaticamente convertido em uma tag a.

Isso também funciona para links de e-mail: estevamsouzalaureth@gmail.com .