Welcome, Guest: Register On Nairaland / LOGIN! / Trending / Recent / NewStats: 3,152,972 members, 7,817,851 topics. Date: Saturday, 04 May 2024 at 09:11 PM |
Nairaland Forum / Science/Technology / The Basic Commands A Software Engineer Must Know About Docker (299 Views)
How To Use Traefik As A Reverse Proxy For Docker Containers / 7 Terms Every Industrial Automation Engineer Must Know (part 2) / 7 Terms Every Industrial Automation Engineer Must Know (part 1) (2) (3) (4)
(1) (Reply)
The Basic Commands A Software Engineer Must Know About Docker by Geesanni: 1:02am On Oct 31, 2022 |
Docker Docker is a tool for developers to create, deploy, and run applications using containers. Containers assist to package the applications, together with all components require such as libraries and other dependencies, and combine together as a single entity so that the application can run on other devices. Docker Component Major Docker components/architecture consists of some main components, namely, registry, image, container, daemon, and client. Registry: This can be called the docker shelf that stores docker images.The Docker registry that we use is called Docker Hub. Image: Images are a read-only template used to build containers.It can be downloaded from the registry directly or implicitly when starting a container.It can be use to transport n application. Container:This is the environment that the docker is been run and wrapped.They can only have access to resource that is define in their configuration Docker daemon: A daemon creates, runs, and monitors containers, along with building and storing images. Client: Docker client allows users to interact with Docker.It allows image to be pulled directly from docke.A client talks to Docker daemon via HTTP. Orchestrate This is the process of managing the life cycle of docker.It is used for automating and controlling the life cycel of docker E.g Kubernetes and docker Swarm. Commands To initialize the swarm mode and listen to a specific interface: Docker swarm init --advertise-addr 10.1.0.2 To join an existing swarm as a manager node: Docker swarm join --token<manager-token> 10.1.0.2:2377 To join a swarm as a worker node: Docker swarm join --token<worker-token> 10.1.0.2:2377 To list all nodes in the swarm: To create a service from an image on the existing port and deploy three instances: Docker service create --replicas 3 -p 80:80 name -webngix To list services running in a swarm: Docker service ls To scale a service: Docker service scale web=5 To list the tasks of a service: Docker service ps web Build The build command is used for building images from a Docker file. Let’s now check out some of the essential Docker build commands. Commands To build an image from the Docker file and tag it: Docker build -t app :1.0 To list all the images that are locally stored: Docker images To delete an image from the Docker Store: Docker rmi alpine: 3.4 Run The run command is used for creating a container from a specified image. Commands To create and run a command: Docker run --name container_name docker_image Flags used: -d: To detach a container on start -rm: To remove a container once it stops -p: To publish the host IP and the host port to the container port -v: To define and share the volume across containers –read-only: To set to the read-only permission Ship Docker allows us to transport our application container anywhere, on any platform. Commands To pull an image from the registry: Docker pull alpine:3.4 To retag a local image with a new image name: Docker tag alpine:3.4 myrepo/ myalpine:3.4 To log in to the registry: Docker login my.registry.com:8000 To push an image to the registry: Docker push myrepo/ myalpine:3.4 Clean up Docker clean up is very importnat so as to free unused resources. Commands To clean an unused/dangling image: Docker image prune To remove an image that is not used in a container: Docker image prune -a To prune the entire system: Docker system prune To leave a swarm: Docker swarm leave To remove a swarm: Docker stack rm stack_name To kill all running containers: Docker kill $ (docker ps -q) To delete all stopped containers: docker rm $(docker ps -a -q) To delete all images: docker rmi $(docker images -q) Services Let’s now take a sneak peek at the commands used to view the running services, to run the services, to view all service logs, and to scale the services. Commands To list all services running in a swarm: Docker service ls To see all running services: Docker stack services stack_name To see all service logs: Docker service logs stack_name service_names To scale a service across qualified nodes: Docker service scale stack_name_service_name= replicas Interaction with a Container Let’s check out how to make an interaction with a container in Docker. Commands To run a command in a container: Docker exe -ti container_name command.sh To follow container logs: Docker logs -ft container name To save a running container as an image: Docker commit -m “commit message” -a “author” container_name username/image_name: tag Important Terms Terminologies used during Docker containerization are listed below: Layer: Read-only files to provision the system Image: Read-only layer that is the base of an image Container: A runnable instance of the image Registry/hub: A central place where images reside Docker machine: A VM to run Docker containers Docker Compose: A VM to run multiple containers as a system Author: Sanni Michael(A senior software Engineer) https://www.linkedin.com/in/sanni-michael-1385a1157/ |
(1) (Reply)
How Long Are Live Scan Fingerprints Good For In California? / UN Chief Calls For Renewable Energy ‘revolution’ For A Brighter Global Future / 4g Intelligent Solar Energy Alert PTZ Camera
(Go Up)
Sections: politics (1) business autos (1) jobs (1) career education (1) romance computers phones travel sports fashion health religion celebs tv-movies music-radio literature webmasters programming techmarket Links: (1) (2) (3) (4) (5) (6) (7) (8) (9) (10) Nairaland - Copyright © 2005 - 2024 Oluwaseun Osewa. All rights reserved. See How To Advertise. 17 |