-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path10 Manage Containers
141 lines (89 loc) · 3.5 KB
/
10 Manage Containers
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
10.1 Manage and configure containers
podman is a project in replacement ot docker
$ sudo dnf install docker
it installs podman-docker(fake docker )
You can edit registries.conf file to make podman point to docker registres
$ vim /etc/containers/registries.conf
comment the unqualified-search-registries, create a new line with the new
unqualified-search-registries = ["docker.io"]
To emulated docker cli using podman :
$ sudo touch /etc/containers/nodocker
To search
$ docker search nginx
To pull an image
$ docker pull docker.io/library/nginx
$ docker pull nginx:1.20.2
To view images on a system
$ docker images
To delete an image, use the image id or image name
$ docker rmi nginx:1.20.2
To run an image to a container
$ docker run nginx:1.20.2
docker run, creates a new container, docker start, starts an old container that was stopped
To run a docker container in detached mode
$ docker run -d nginx
To explore running containers
$ docker ps
or
$ docker container list
To stop a container, you can user the name or id
$ docker stop <container_id>
To view all(active and stoppped) containers
$ docker ps --all
or
$ docker ps -a
To delete a container (must be stopped first)
$ docker rm <container_name>
NB: You can not delete an image that is used by container
You can force, it will stop and delete the container
$ docker rmi -force nginx
You can force and delete a container
$ docker rm --force <container-name>
You can name a container
$ docker run -d -p 8080:80 --name mywebserver nginx
port-mapping : 8080 on host : 80 on container
10.2 Perform container management using commands such as podman and skopeo
Installing skopeo
$ sudo yum install skopeo
Inspecting Repositories
$ skopeo inspect docker://registry.fedoraproject.org/fedora:latest
Inspect containers
$ skopeo inspect --config docker://registry.fedoraproject.org/fedora:latest | jq
Copying Images
$ skopeo copy docker://quay.io/buildah/stable docker://registry.kodekloud.com/buildah
$ skopeo copy oci:busybox_ocilayout:latest dir:myemptydirectory
Deleting images
$ skopeo delete docker://localhost:5000/imagename:latest
syncing Registries
$ sudo skopeo sync --src docker --dest dir registry.fedoraproject.org/fedora:latest /home/bob/fedora
10.3 Configure a container to start automatically as a systemd service and attach persistent storage
To swith module streams
$ sudo yum module reset container-tools
$ sudo yum module install container-tools:3.0
Create a directory for service definition
$ mkdir -p ~/.config/systemd/user
Create a directory for persistent storage
$ mkdir ~/container_storage
Populate the storage directory with some content
$ echo "KodeKloud" > ~/container_storage/kodekloud.html
Create a container to generate unit files
$ podman run -d --name container_service -p 1025:8080 -v ~/container_storage:/var/www/html:Z registry.access.redhat.com+rhscl/httpd-24-rhel7
Test container
$ curl 127.0.0.1:1025/kodekloud.html
Create the systemd unit file
$ cd ~/.config/systemd/user
$ podman generate systemd --name container_service --files --new
This command will generate a service file container-(name).service
Kill and remove the currently running container
$ podman kill container_service
and
$ podman rm container_service
Enable a loggin setting for the user
$ loginctl enable-linger
$ systemctl --user daemon-reload
$ systemctl --user enable --now container-(name).service
-- PRACTICE
loginctl enable-linger bob
export XDG_RUNTIME_DIR=/run/user/$(id -u)
systemctl --user daemon-reload
systemctl --user enable container-kodekloud.service --now