Docker

Docker

Commands Descriptions
docker create creates a container but does not start it.
docker image ls List all images that are locally stored with the Docker Engine.
docker container run Creates and starts a container in one operation.
docker rm Deletes a container.
docker update Updates a container’s resource limits.

Docker Run Commands

Commands Descriptions docker run -d -p 3000:80 laravel-php:7.3 -d To run the container in the background process. “-p 3000:80” expose port 3000 externally and map to port 80. “laravel-php:7.3” container name docker stop laravel-php:7.3 Stop a running container through SIGTERM docker kill laravel-php:7.3 Stop a running container through SIGKILL docker rm -f $(docker ps -aq) Delete all running and stopped containers docker ps List the running containers docker ps –a To see all the running and stopped containers docker exec -it web bash Create a new bash process inside the container and connectit to the terminal docker logs –tail 100 web Print the last 100 lines of a container’s logs docker events Get Events

Docker Build Commands

Commands Descriptions docker build -t laravel-php:7.3 Build an image from the Dockerfile in the current directory and tag the image docker images List all images that are locally stored with the Docker Engine docker rmi laravel-php:7.3 Delete an image from the local image store

Docker Deploy Commands

Commands Descriptions
docker login Log in to a Docker Hub registry.
docker pull image-name Pull an image from registry.
docker tag image-name Retag a local image with a new image name and tag.
docker push image-name Push image to docker registry.

Docker Commands Basic Structure

Image — A snapshot file of a container. Create containers by pulling and running Docker Images. Docker Hub / Registry* — A public cloud-based registry service for developers to share their code on.

[options] — Add options to your Docker commands to change the results. Each command has multiple options available. [command] — Enter the parameters for the Docker command, this could be a filename or container ID. [arg] — Set additional argument variables. [env] — Use to configure environment variables. [init] — Initialize a swarm (by default, Docker will designate chosen machine as manager node). [ca] — Show root Certificate Authority (auto-generated by init command). [join] — Join a swarm as a worker/manager node. [join-token] — Manage join tokens—define worker or manager accordingly. [leave] — When implemented on a worker, the command prompts the node to leave the swarm. [–force] — When implemented on a manager, the command forces the node to leave the swarm. [tag] — The tag parameter is often part of the image name, but as your swarm develops you can adjust the tag without changing the base image name. [unlock] — Unlock swarm manager with a user-own unlock key. [unlock-key] — Manage the unlock key, useful to unlock a manager node. [update] — Update the swarm.

Starting & Stopping Containers

Starting: docker start nginx

Stopping: docker stop nginx

Restarting: docker restart nginx

Pausing: docker pause nginx

Unpausing: docker unpause nginx

Blocking a Container: docker wait nginx

Sending a SIGKILL: docker kill nginx

Connecting to an Existing Container: docker attach nginx


Getting Information about Containers

Running Containers: docker ps / docker ps -a

Container Logs: docker logs infinite

Inspecting Containers: docker inspect infinite / docker inspect –format ‘{{ .NetworkSettings.IPAddress }}’ $(docker ps -q)

Containers Events: docker events infinite

Public Ports: docker port infinite

Running Processes: docker top infinite

Container Resource Usage: docker stats infinite

Inspecting changes to files or directories on a container’s filesystem: docker diff infinite