Comandos Essenciais do Docker

Sumário
- Docker CLI Cheat Sheet
- Table of content 📎
- Docker Images
- Pull image from Docker Hub
- Search
- Create new image
- Build an image
- Pushing the image
- Removing the image
- Docker Container
- Creating a container
- Running the container
- Renaming the container
- Updating the container
- Container Start, Stop and Restart
- Pausing and Resuming
- Removing the container
- Information’s related to Container
- Docker Networks
- Creating a Network
- Listing all Network
- Inspecting a Network
- Removing
- Connect & Disconnecting container from a network
- GitHub Flavored Markdown
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_worldSearch
To search for any image available in docker hub includes additional filter option.
docker search imageName
docker search naveenv24/hello_worldCreate 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.renamedPushing 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_worldRemoving the image
This command will help you remove the image from your environment if it’s not having any dependency. Include
-fto forcefully remove.rmiimplies remove-image.
docker rmi -f imageName
docker rmi naveenv24/hello_worldDocker 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.
-timplies target-Iimplies the image name.
docker create – t -I ImageName --name ContainerName
docker create – t -I naveenv24/hello_world --name hw-containerRunning the container
This command will create the container if not created and starts the container the
-itimplies interactive mode and-dimplies detach mode which run the container background
docker run –name containerName -it -d imageName
docker run –name hw-container -it -d naveenv24/hello_worldRenaming the container
This command will rename you’re container name
docker rename oldContainerName newContainerName
docker rename hw-container hw-con-newUpdating 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 containerNameContainer Start, Stop and Restart
Stop the running container or start the non running container or use restart to perform both.
-twait 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-newPausing 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-newRemoving 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-newInformation’s related to Container
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 statisticsDocker 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 mynetworkListing all Network
To view all the available networks in the docker
docker network lsInspecting a Network
To view the detailed information about the network
docker network inspect networkName
docker network inspect mynetworkRemoving
To remove the network from the available list
docker network rm networkName
docker network rm mynetworkConnect & Disconnecting container from a network
To connect the container from the network
docker network connect networkName containerName
docker network connect mynetwork hw-con-newTo disconnect the container from the network
docker network disconnect networkName containerName
docker network disconnect mynetwork hw-con-newThese 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 .

