Docker: Tasks 101 
So in my opinion containers are more like chroot-in-steroids isolation than fully virtualized environments. That's how it feels to me so far as of 4/11/2018. - Angel


# installing docker (1.10.3)
[aesteban@localhost ~]$ sudo dnf install docker

# start and enable it
[aesteban@localhost ~]$ sudo systemctl start docker
[aesteban@localhost ~]$ sudo systemctl enable docker

# download and run hello-world image
[aesteban@localhost ~]$ sudo docker run hello-world

# download ubuntu image and run it
[aesteban@localhost ~]$ sudo docker run -it ubuntu bash

# listing images
[aesteban@localhost ~]$
[aesteban@localhost ~]$ sudo docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
docker.io/hello-world latest e38bc07ac18e 3 hours ago 1.848 kB
docker.io/ubuntu latest f975c5035748 5 weeks ago 112.4 MB
[aesteban@localhost ~]$

# listing all containers
[aesteban@localhost ~]$
[aesteban@localhost ~]$ sudo docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
61d35d591f53 ubuntu "bash" 3 minutes ago Exited (0) 3 minutes ago clever_brahmagupta
1c61c7a6f4d7 hello-world "/hello" 4 minutes ago Exited (0) 4 minutes ago tiny_boyd
[aesteban@localhost ~]$

# removing a container (container id)
[aesteban@localhost ~]$
[aesteban@localhost ~]$ sudo docker rm 61d35d591f53
61d35d591f53
[aesteban@localhost ~]$

# removing an image (image id)
[aesteban@localhost ~]$ sudo docker rmi f975c5035748
Untagged: docker.io/ubuntu:latest
Untagged: docker.io/ubuntu@sha256:e348fbbea0e0a0e73ab0370de151e7800684445c509d46195aef73e090a49bd6
Deleted: sha256:f975c50357489439eb9145dbfa16bb7cd06c02c31aa4df45c77de4d2baa4e232
Deleted: sha256:0bd983fc698ee9453dd7d21f8572ea1016ec9255346ceabb0f9e173b4348644f
Deleted: sha256:08fe90e1a1644431accc00cc80f519f4628dbf06a653c76800b116d3333d2b6d
Deleted: sha256:5dc5eef2b94edd185b4d39586e7beb385a54b6bac05d165c9d47494492448235
Deleted: sha256:14a40a140881d18382e13b37588b3aa70097bb4f3fb44085bc95663bdc68fe20
Deleted: sha256:a94e0d5a7c404d0e6fa15d8cd4010e69663bd8813b5117fbad71365a73656df9
[aesteban@localhost ~]$

# deleting all containers
[aesteban@localhost ~]$ sudo docker rm $(sudo docker ps -a -q)
1c61c7a6f4d7
[aesteban@localhost ~]$

# deleting all images
[aesteban@localhost ~]$
[aesteban@localhost ~]$ sudo docker rmi $(sudo docker images -q)
Untagged: docker.io/hello-world:latest
Untagged: docker.io/hello-world@sha256:6c88d0eedd6a5e71f0affaf150f8b7b286c7bdc679f23d726d12781803e727d3
Deleted: sha256:e38bc07ac18ee64e6d59cf2eafcdddf9cec2364dfe129fe0af75f1b0194e0c96
Deleted: sha256:2b8cbd0846c5aeaa7265323e7cf085779eaf244ccbdd982c4931aef9be0d2faf
[aesteban@localhost ~]$

# installing docker-compose
[aesteban@localhost ~]$ sudo dnf install docker-compose

# saving a modified container (eg. after installing RPMs)
[aesteban@localhost ~]$ sudo docker commit "container-id" "image_name" # repo name

#
[aesteban@localhost ~]$ sudo docker start "container-id"

#
[aesteban@localhost ~]$ sudo docker attach "container-id"

# exporting an image to a file
[aesteban@localhost ~]$ sudo docker save "image-id" | gzip -c image_name.tgz

# importing an image from a file
[aesteban@localhost ~]$ sudo docker load < image_name.tgz

# sample docker-compose.yml
[aesteban@localhost docker-practice]$ cat docker-compose.yml
web:
image: nginx:latest
ports:
- "8888:80"
volumes:
- ./code:/code
- ./site.conf:/etc/nginx/conf.d/site.conf
links:
- php
php:
image: cytopia/php-fpm-7.1 # could also be and id (imageid? or containerid? I think the first.)
volumes:
- ./code/:/code/
[aesteban@localhost docker-practice]$

# executing docker-compose.yml
[aesteban@localhost docker-practice]$ sudo docker-compose up
...

# sample docker file
[aesteban@localhost docker-practice]$ cat Dockerfile
FROM miveo/centos-php-fpm:7.1
RUN yum -y install php71u-pecl-memcached.x86_64
[aesteban@localhost docker-practice]$
[aesteban@localhost docker-practice]$

# building a docker file
[aesteban@localhost docker-practice]$ sudo docker build -t ent:ent .
...

# verifying build
[aesteban@localhost docker-practice]$
[aesteban@localhost docker-practice]$ sudo docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
ent ent 3d83d51abac9 About a minute ago 429.3 MB
docker.io/nginx latest b175e7467d66 27 hours ago 108.9 MB
docker.io/cytopia/php-fpm-7.1 latest 927ad858fb6a 7 months ago 1.098 GB
docker.io/miveo/centos-php-fpm 7.1 95cae7821f24 15 months ago 287.6 MB
[aesteban@localhost docker-practice]$
[aesteban@localhost docker-practice]$ sudo docker run -it 3d83d51abac9 bash
[root@43bb9a049b54 /]#
[root@43bb9a049b54 /]# rpm -qa | grep php | grep memcached
php71u-pecl-memcached-3.0.4-2.ius.centos7.x86_64
[root@43bb9a049b54 /]#
[root@43bb9a049b54 /]#


12/11/2018

#stop container id
[aesteban@localhost docker-practice-2]$ sudo docker stop 2d900ed18675
2d900ed18675
[aesteban@localhost docker-practice-2]$


Comments
Comments are not available for this entry.
2024 By Angel Cool