Otu esi etinye ma jiri Docker na Ubuntu 20.04


Docker bụ ikpo okwu mepere emepe maka mmepe, mbupu na ngwa na-agba ọsọ nke na-eji ikike ọkwa ọkwa OS na-ebuga sọftụwia na ngwugwu akpọrọ Containers. Ozugbo etinyere ya, jiri akụrụngwa sistemụ arụ ọrụ nke nnabata. Nke a pụtara na ha na-arụ ọrụ nke ọma karịa hypervisors (igwe mebere) na usoro akụrụngwa. Kama ịmegharị ngwaike, arịa na-adabere n'elu otu ihe atụ Linux.

N'ime nkuzi a, ị ga-amụta otu esi etinye ma jiri Docker na sistemụ arụmọrụ Ubuntu 20.04 gị.

Prerequisites

  • OS akwadoro: Ubuntu 20.04 - nhọrọ (Ubuntu 21.04)
  • Akaụntụ onye ọrụ: Akaụntụ onye ọrụ nwere sudo ma ọ bụ ohere mgbọrọgwụ.
  • Ngwungwu achọrọ: curl

Na-emelite Sistemụ Ọrụ

Melite gi Ubuntu 20.04 sistemụ arụmọrụ iji hụ na ngwugwu niile dị kwalitere ruo ugbu a:

sudo apt update && sudo apt upgrade

Wụnye ngwugwu achọrọ

Iji wụnye Docker nke ọma, ị ga-achọ ịwụnye ngwugwu ndị a; gbaa iwu a ma ọ bụrụ na ị maghị; ọ gaghị emerụ gị usoro.

sudo apt install apt-transport-https ca-certificates curl software-properties-common curl

Advertisement


Wụnye ọkpọ

Bubata igodo na ebe nchekwa GPG

Nzọụkwụ mbụ na ntinye Docker bụ ibubata igodo GPG na iwu na-esonụ:

curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -

Mwepụta ihe atụ ma ọ bụrụ na ọ ga nke ọma:

OK

Ọzọ, bubata ebe nchekwa ahụ na ndepụta isi mmalite APT gị dị ka ndị a:

sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu focal stable"

Ugbu a megharịa ndepụta nchekwa APT gị ka ọ gosipụta mgbakwunye ọhụrụ ebe nchekwa:

sudo apt update

Wụnye ọkpọ

Iji igodo GPG na ebe nchekwa ebubatara, ị nwere ike ịga n'ihu ịwụnye Docker site na iji iwu a:

sudo apt install docker-ce

Ihe atụ mmepụta:

Otu esi etinye ma jiri Docker na Ubuntu 20.04

ụdị Y, pịa pịa Tinye bọtịnụ ịga n'ihu na nwụnye.

Na-esote, kwado nrụnye site na ịlele ụdị/ewu dị ka ndị a:

docker -v

Ihe atụ mmepụta:

Docker version 20.10.8, build 3967b7d

Nhọrọ ọzọ bụ iji apt-cache policy:

sudo apt-cache policy docker-ce

Ihe atụ mmepụta:

Ugbu a, site na ndabara, ọrụ maka Docker kwesịrị ịmalite na-akpaghị aka na Ubuntu 20.04. Iji nyochaa nke a, jiri systemctl iwu iwu ịlele:

systemctl status docker

Ihe atụ mmepụta:

Ọ bụrụ n'obere ohere etinyebeghị Docker, jiri iwu a ka ịmalite ọrụ:

sudo systemctl start docker

Iji mee ka Docker malite na buut sistemụ, jiri iwu a:

sudo systemctl enable docker

Ụfọdụ ndị ọzọ bara uru systemctl nyere iwu mara maka Docker:

Malitegharịa Docker:

sudo systemctl restart docker

Kwụsị Docker:

sudo systemctl stop docker

Gbanyụọ Docker site na autostart na buut sistemụ:

sudo systemctl disable docker

Nhọrọ - Tinye onye ọrụ na otu Docker

Site na ndabara, Docker nwere ike iji naanị mgbọrọgwụ na iwu sudo. Maka ọtụtụ ndị ọrụ, ọkachasị ndị bụ naanị ndị ọrụ na sistemụ arụmọrụ, ọ bụghị nnukwu ihe, mana ọ bụrụ na ị ga-ewepụ iwu ndị ọzọ, ịkwesịrị ịgbakwunye aha njirimara gị na otu Docker.

Ihe Nlereanya:

docker: Cannot connect to the Docker daemon. Is the docker daemon running on this host?.
See 'docker run --help'.

Iji zere nke a, ma zere iji mgbọrọgwụ ma ọ bụ sudo iwu, tinye aha njirimara gị na Docker na ya otu onye ọrụ. Iji mee nke a, jiri iwu a:

sudo usermod -aG docker ${USER}

Ọzọ, iji tinye mgbanwe ahụ, ị ​​ga-achọ ịpụ apụ wee banye azụ. Iji mee nke a, jiri iwu a:

su - ${USER}

Ugbu a, ị ga-akwado na agbakwunyere onye ọrụ gị na docker otu site na ịpị:

id -nG

Ihe atụ mmepụta:

joshua sudo docker

N'aka nke ọzọ, iji tinye onye ọrụ ọzọ na otu docker, ị nwere ike ime ya site na iji iwu a:

sudo usermod -aG docker username

Advertisement


Otu esi eji Docker

Otu esi eji Iwu

Iji jiri Docker, ị ga-achọ ịmụta nhọrọ na iwu. Ọmụmaatụ ka nke a si yie:

sudo docker [option] [command]

Ugbu a, ezigbo mmalite bụ ilele iwu niile dị:

Usage:  docker [OPTIONS] COMMAND

A self-sufficient runtime for containers

Options:
      --config string      Location of client config files (default
                           "/home/joshua/.docker")
  -c, --context string     Name of the context to use to connect to the
                           daemon (overrides DOCKER_HOST env var and
                           default context set with "docker context use")
  -D, --debug              Enable debug mode
  -H, --host list          Daemon socket(s) to connect to
  -l, --log-level string   Set the logging level
                           ("debug"|"info"|"warn"|"error"|"fatal")
                           (default "info")
      --tls                Use TLS; implied by --tlsverify
      --tlscacert string   Trust certs signed only by this CA (default
                           "/home/joshua/.docker/ca.pem")
      --tlscert string     Path to TLS certificate file (default
                           "/home/joshua/.docker/cert.pem")
      --tlskey string      Path to TLS key file (default
                           "/home/joshua/.docker/key.pem")
      --tlsverify          Use TLS and verify the remote
  -v, --version            Print version information and quit

Management Commands:
  app*        Docker App (Docker Inc., v0.9.1-beta3)
  builder     Manage builds
  buildx*     Build with BuildKit (Docker Inc., v0.6.1-docker)
  config      Manage Docker configs
  container   Manage containers
  context     Manage contexts
  image       Manage images
  manifest    Manage Docker image manifests and manifest lists
  network     Manage networks
  node        Manage Swarm nodes
  plugin      Manage plugins
  scan*       Docker Scan (Docker Inc., v0.8.0)
  secret      Manage Docker secrets
  service     Manage services
  stack       Manage Docker stacks
  swarm       Manage Swarm
  system      Manage Docker
  trust       Manage trust on Docker images
  volume      Manage volumes

Commands:
  attach      Attach local standard input, output, and error streams to a running container
  build       Build an image from a Dockerfile
  commit      Create a new image from a container's changes
  cp          Copy files/folders between a container and the local filesystem
  create      Create a new container
  diff        Inspect changes to files or directories on a container's filesystem
  events      Get real time events from the server
  exec        Run a command in a running container
  export      Export a container's filesystem as a tar archive
  history     Show the history of an image
  images      List images
  import      Import the contents from a tarball to create a filesystem image
  info        Display system-wide information
  inspect     Return low-level information on Docker objects
  kill        Kill one or more running containers
  load        Load an image from a tar archive or STDIN
  login       Log in to a Docker registry
  logout      Log out from a Docker registry
  logs        Fetch the logs of a container
  pause       Pause all processes within one or more containers
  port        List port mappings or a specific mapping for the container
  ps          List containers
  pull        Pull an image or a repository from a registry
  push        Push an image or a repository to a registry
  rename      Rename a container
  restart     Restart one or more containers
  rm          Remove one or more containers
  rmi         Remove one or more images
  run         Run a command in a new container
  save        Save one or more images to a tar archive (streamed to STDOUT by default)
  search      Search the Docker Hub for images
  start       Start one or more stopped containers
  stats       Display a live stream of container(s) resource usage statistics
  stop        Stop one or more running containers
  tag         Create a tag TARGET_IMAGE that refers to SOURCE_IMAGE
  top         Display the running processes of a container
  unpause     Unpause all processes within one or more containers
  update      Update configuration of one or more containers
  version     Show the Docker version information
  wait        Block until one or more containers stop, then print their exit codes

Ka ilele ozi ndị ọzọ gbasara iwu, jiri iwu na-esonụ iji gosipụta ozi ndị ọzọ.

sudo docker <command> --help

Dịka ọmụmaatụ, nkuzi a ga-egosipụta ozi enyemaka gbasara iwu ntinye na docker:

Ka ilele ozi gbasara sistemụ docker na sistemụ gị, jiri iwu a:

sudo docker info

Ihe atụ mmepụta:

Client:
 Context:    default
 Debug Mode: false
 Plugins:
  app: Docker App (Docker Inc., v0.9.1-beta3)
  buildx: Build with BuildKit (Docker Inc., v0.6.1-docker)
  scan: Docker Scan (Docker Inc., v0.8.0)

Server:
 Containers: 0
  Running: 0
  Paused: 0
  Stopped: 0
 Images: 0
 Server Version: 20.10.8
 Storage Driver: overlay2
  Backing Filesystem: extfs
  Supports d_type: true
  Native Overlay Diff: true
  userxattr: false
 Logging Driver: json-file
 Cgroup Driver: cgroupfs
 Cgroup Version: 1
 Plugins:
  Volume: local
  Network: bridge host ipvlan macvlan null overlay
  Log: awslogs fluentd gcplogs gelf journald json-file local logentries splunk syslog
 Swarm: inactive
 Runtimes: io.containerd.runc.v2 io.containerd.runtime.v1.linux runc
 Default Runtime: runc
 Init Binary: docker-init
 containerd version: e25210fe30a0a703442421b0f60afac609f950a3
 runc version: v1.0.1-0-g4144b63
 init version: de40ad0
 Security Options:
  apparmor
  seccomp
   Profile: default
 Kernel Version: 5.11.0-34-generic
 Operating System: Ubuntu 20.04.3 LTS
 OSType: linux
 Architecture: x86_64
 CPUs: 4
 Total Memory: 3.81GiB
 Name: ubuntu
 ID: CLA2:OOBD:5BJW:4WPT:4Y7L:ZGS6:VNIL:JGV4:ZTUA:IG3S:BGX7:Z626
 Docker Root Dir: /var/lib/docker
 Debug Mode: false
 Registry: https://index.docker.io/v1/
 Labels:
 Experimental: false
 Insecure Registries:
  127.0.0.0/8
 Live Restore Enabled: false

Enwere ike ịnweta otu esi anwale onyonyo Docker

Iji ghọta ka Docker si arụ ọrụ, a na-ewu akpa Docker site na onyonyo Docker ewepụtara na ya Ogwe Docker nke ụlọ ọrụ mepụtara Docker nwe ma na-elekọta ya. Docker Hub na-enye onye ọ bụla ohere ịnabata onyonyo Docker ha, yabụ na-akwado ọtụtụ ngwa na nkesa Linux na Hub.

Nnwale mbụ bụ ijide n'aka na enwere ike ịnweta Docker Hub, yana ị nwere ike budata onyonyo site na Hub Docker. Iji mee nke a, jiri iwu a:

sudo docker run hello-world

Ugbu a, ihe mbụ ị nwere ike ịhụ bụ mmepụta Enweghị ike ịhụ foto 'hello-world: latest' na mpaghara." Echegbula; nke a bụ ihe nkịtị, yana dabere na njikọ ịntanetị gị, ngwa docker kwesịrị ịdọrọ onyonyo ọhụrụ na Docker Hub, ebe nchekwa ndabere.

Mwepụta ihe atụ ma ọ bụrụ na ọ ga nke ọma:

Ugbu a ebudatara onyonyo Docker dị ka n'elu, Docker mepụtara akpa ọhụrụ site na onyonyo aha ya Ndewo Ụwa.

Otu esi achọ ihe onyonyo Docker

Ka ịchọọ onyonyo dị na Docker Hub site na iji iwu nchọ docker.

Ihe Nlereanya:

docker search ubuntu

Ihe atụ mmepụta:

Dịka n'elu, ndepụta onyonyo niile aha dabara na eriri iwu ọchụchọ ị mebiri. Mgbe nkọwa ahụ gasịrị, ị nwere ike ịhụ ogidi atọ.

  • Kpakpando - Ọnụọgụ votu enwetara na obodo, elu na-adị mma mgbe niile.
  • Onye isi - Foto ndị ụlọ ọrụ Docker wuru ma kwado ya.
  • Akpaaka - Onyonyo arụpụtara site na obodo, ndị ụlọ ọrụ Docker akwadoghị nke ọma. Jiri n'ihe egwu nke aka gị.

Otu esi adọta onyonyo Docker

Mgbe ịchọọ ihe oyiyi, ị nwere ike ịdọrọ ndị a na docker ịdọrọ iwu.

docker pull ubuntu

Ihe atụ mmepụta:

Na-esote, gosi na onyonyo dị na sistemụ gị:

docker images

Ihe atụ mmepụta:

Dị ka n'elu, ị nwetara ubuntu oyiyi na mbụ ndewo-ụwa oyiyi ị mepụtara na mbụ na nkuzi maka ebumnuche ule. Mwepụta ahụ na-enyekwa ozi na mkpado, id oyiyi, okike na nha.

Otu esi agba akpa Docker site na onyonyo

Ugbu a ị mụtala ihe ndị bụ isi, ị nwere ike ime ihe oyiyi ubuntu nke ebudatara ugbu a. Iji mee nke a, jiri iwu na-esonụ ya na ọkọlọtọ -it nke ga-enye gị ohere ịnweta akpa ahụ site na iji ohere shei:

docker run -it ubuntu

Rịba ama, dị ka ọ dị na ndewo-okwu ọmụmaatụ, ọ bụrụ na ebudatabeghị onyonyo, a docker agba ọsọ iwu Egburu, onye ahịa Docker ga-ebu ụzọ budata onyonyo a wee jiri ya rụọ akpa ahụ.

Ị ga-anọ ugbu a n'ime akpa shei, dịka ị ga-ahụ na mmepụta ndị a:

root@75b1115bacfd:/# 

Mmepụta ga-egosipụta nke gị akpa ID, nke n'ihe banyere nkuzi bụ 75b1115 bat. Biko mara NJ a, n'ihi na ị ga-achọ ya maka ebumnuche njikwa, dị ka iwepụ akpa ahụ n'oge ọzọ.

Otu esi etinye ngwugwu na Docker Container

Ịwụnye ngwugwu n'ime akpa Docker gị dị mfe; ọ bụ otu ihe ahụ dị ka ịrụ ọrụ na sistemụ Ubuntu gị.

Dịka ọmụmaatụ, ịnwere ike ịnwale site na ịtinye ụfọdụ ngwugwu.

Wụnye ngwa Nginx:

apt install nginx

Ihe atụ mmepụta:

ụdị Y, pịa pịa Tinye bọtịnụ ịga n'ihu na nwụnye.

O yikarịrị ka ị ga-enweta ngwa ngwa ịhọrọ mpaghara mpaghara gị na ntinye ngwugwu oge mbụ.

Ihe Nlereanya:

Họrọ mpaghara mpaghara kacha nso gị site na ịpị nọmba wee pịa ya Tinye igodo.

Na-esote, a ga-akpali gị ịhọrọ obodo kaboodu; dị ka ọ dị na mpaghara mpaghara, họrọ ebe nchekwa ma kụọ ya Tinye igodo.

Ihe Nlereanya:

Nyochaa nwụnye Nginx na akpa Docker gị site na iji iwu ụdị a:

nginx -v
nginx version: nginx/1.18.0 (Ubuntu)

Otu esi emelite ngwugwu n'ime akpa Docker

Ka imelite ngwugwu n'ime akpa Docker, ị nwere ike iji iwu mmelite dabara adaba na-enweghị sudo ma ọ bụ mgbọrọgwụ n'ihi na ị na-arụ ọrụ dị ka onye ọrụ mgbọrọgwụ akpa ahụ.

Ihe Nlereanya:

apt update

Mgbe ahụ kwalite dị ka ị ga-asị na ị na-arụ ọrụ na sistemụ arụmọrụ Ubuntu gị:

apt upgrade 

Otu esi ewepu ngwugwu n'ime akpa Docker

Usoro iwepụ ngwugwu n'ime akpa Docker gị bụ otu ịwụnye ha na akpa gị. Iji wepu ngwugwu ị rụnyere na mbụ, maka ọmụmaatụ anyị ọ bụ Nginx, jiri iwu a:

apt autoremove nginx

Ihe atụ mmepụta:

ụdị Y, pịa pịa Tinye bọtịnụ ka ịga n'ihu na iwepụ ya.

Otu esi esi pụọ na akpa Docker

Iji pụọ na akpa Docker gị, jiri iwu a:

exit

Otu esi edepụta arịa Docker

Ugbu a ịpụla dị ka n'elu laghachi na isi sistemụ arụmọrụ gị. Ị nwere ike iji docker ps iwu nke ahụ ga-edepụta iwu Docker arụ ọrụ na sistemụ gị:

sudo docker ps

Ihe atụ mmepụta:

Iwu ọzọ bụ iji docker ps na - ọkọlọtọ, na nke a ga-edepụta arịa Docker niile na-arụ ọrụ yana ndị anaghị arụ ọrụ.

sudo docker ps -a

Ihe atụ mmepụta:

Dịka ị na-ahụ n'elu, enwere otu akpa na-arụ ọrụ na ihe abụọ anaghị arụ ọrụ.

Iwu ọzọ dị mma bụ docker ps with the -l ọkọlọtọ, ndepụta akpa e kere ikpeazụ.

sudo docker ps -l

Ihe atụ mmepụta:

Rịba ama aha arịa ndị ahụ; ị nwere ike iji ndị a kama IDS akpa; ọmụmaatụ, n'elu, akpa ID 5c9785bbfd75 aha musing_lehmann.

Otu esi amalite akpa Docker

Iji malite akpa Docker, ị ga-enweta ya akpa ID nke, ọ bụrụ na echefuru ya, enwere ike ịhụ ya ngwa ngwa site na iji iwu docker ps. Na-esote, mebie iwu a dị ka ọmụmaatụ nke ịmalite akpa:

sudo docker start 5c9785bbfd75

Iji nyochaa ọkwa ka ịhụ ma ọ na-arụ ọrụ, jiri iwu docker ps:

sudo docker ps

Ihe atụ mmepụta:

Dịka ị na-ahụ, ID akpa 5c9785bbfd75 na-arụ ọrụ ugbu a.

Otu esi akwụsị igbe docker

Ịkwụsị akpa Docker bụ otu ihe ahụ dị ka ịmalite akpa ahụ mana n'aka ya na nhọrọ nkwụsị ejiri.

sudo docker stop 5c9785bbfd75

Ugbu a jiri iwu docker ps ọzọ ịhụ ọkwa:

Ihe atụ mmepụta:

Dịka n'elu, ị nwere ike ịhụ ID akpa 5c9785bbfd75 adịghị arụ ọrụ ugbu a.

Otu esi ewepu igbe docker

Ozugbo ịmechara ma ọ bụ achọkwaghị akpa ahụ, ị ​​nwere ike wepu ya site na iji iwu docker rm na ya akpa ID ma ọ bụ na akpa aha. Ọmụmaatụ, wepuo akpa ule ndewo-uwa.

sudo docker rm 7f00ad33be63

N'aka nke ọzọ, ịnwere ike ihichapụ ID akpa gị site na aha Docker kenyere. Na nkuzi, na Akpọrọ ID akpa 7f00ad33be63 (akpa ndewo-ụwa) aha ya bụ nifty_gagarin. Iji wepụ ya, jiri ihe ndị a:

sudo docker rm nifty_gagarin

Ihe atụ mmepụta:

Okwu na mmechi

N'ime nkuzi a, ị mụtara ka esi etinye Docker na Ubuntu 20.04, jiri ihe onyonyo na arịa rụọ ọrụ. Site na ebe a, ị nwere ike ịga n'ihu na-amụta maka otu esi agbagharị na ịme mgbanwe na Docker Hub ma ọ bụrụ na ịchọrọ ịkekọrịta ma ọ bụ kwadoo onyonyo. Ịdebanye aha maka akaụntụ bụ n'efu, na ọtụtụ atụmatụ dị oke ọnụ, na azụmahịa bụ nke kachasị elu na dollar 21; ọ bụrụ na ọ nwere mmasị, gaa na ibe ndebanye aha ma mepụta akaụntụ.

N'ozuzu, Docker na-ewu ewu nke ukwuu ka ọ na-agbanwe ka a na-eme mmepe ụbọchị ndị a na ịdị mfe iji ya, nchekwa na ihe onwunwe anụ ahụ bụ obere igwe mebere dị ka a hụrụ n'elu ikpo okwu na ụlọ ọrụ ngwanrọ. Arụmụka a na-amalite ugbu a na nke dị nchebe karịa n'etiti igwe mebere na docker. Agbanyeghị, ha abụọ nwere ike ịdị ize ndụ, yana omume dị mma nwere ike kwụsị ọtụtụ nsogbu nchekwa na ihe ọ bụla ị họọrọ.

Idenye aha
Gwa nke
1 Comment
Inline nzaghachi
Lee echiche niile

ya mere!
<3

Emeziri ikpeazụ ụbọchị 19 gara aga site na coucou
1
0
Ga-ahụ n'anya gị echiche, biko okwu.x