Thanks to visit codestin.com
Credit goes to www.scribd.com

0% found this document useful (0 votes)
22 views6 pages

Docker Basic

The document provides a comprehensive guide on installing and using Docker on a Debian system, including commands for updating the system, installing Docker, pulling images, and running containers. It also covers creating Docker volumes and using Docker Compose to manage multi-container applications. Additionally, it includes examples of setting up an Apache server with PHP and managing Docker volumes through Docker commands.

Uploaded by

santosadidik543
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
22 views6 pages

Docker Basic

The document provides a comprehensive guide on installing and using Docker on a Debian system, including commands for updating the system, installing Docker, pulling images, and running containers. It also covers creating Docker volumes and using Docker Compose to manage multi-container applications. Additionally, it includes examples of setting up an Apache server with PHP and managing Docker volumes through Docker commands.

Uploaded by

santosadidik543
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 6

Docker Administrator

apt update

apt install sudo curl

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

curl -fsSL https://download.docker.com/linux/debian/gpg | sudo gpg --dearmor -o


/usr/share/keyrings/docker-archive-keyring.gpg
echo "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/docker-archive-
keyring.gpg] https://download.docker.com/linux/debian $(lsb_release -cs) stable" | sudo tee
/etc/apt/sources.list.d/docker.list > /dev/null

apt update

sudo apt install -y docker-ce docker-ce-cli containerd.io

root@DockerSRV:~# docker version


Client: Docker Engine - Community
Version: 28.0.2
API version: 1.48
Go version: go1.23.7
Git commit: 0442a73
Built: Wed Mar 19 14:36:58 2025
OS/Arch: linux/amd64
Context: default

Server: Docker Engine - Community


Engine:
Version: 28.0.2
API version: 1.48 (minimum version 1.24)
Go version: go1.23.7
Git commit: bea4de2
Built: Wed Mar 19 14:36:58 2025
OS/Arch: linux/amd64
Experimental: false
containerd:
Version: 1.7.25
GitCommit: bcc810d6b9066471b0b6fa75f557a15a1cbf31bb
runc:
Version: 1.2.4
GitCommit: v1.2.4-0-g6c52b3f
docker-init:
Version: 0.19.0
GitCommit: de40ad0

root@DockerSRV:~# docker pull nginx


Using default tag: latest
latest: Pulling from library/nginx
6e909acdb790: Pull complete
5eaa34f5b9c2: Pull complete
417c4bccf534: Pull complete
e7e0ca015e55: Pull complete
373fe654e984: Pull complete
97f5c0f51d43: Pull complete
c22eb46e871a: Pull complete
Digest:
sha256:124b44bfc9ccd1f3cedf4b592d4d1e8bddb78b51ec2ed5056c52d3692ba
ebc19
Status: Downloaded newer image for nginx:latest
docker.io/library/nginx:latest

docker run --name my-nginx -p 8080:80 -d nginx

root@DockerSRV:~# docker ps
CONTAINER ID IMAGE COMMAND CREATED
STATUS PORTS NAMES
13b984660f3e nginx "/docker-entrypoint.…" 5 seconds ago
Up 4 seconds 0.0.0.0:8080->80/tcp, [::]:8080->80/tcp my-nginx
root@DockerSRV:~#

Web browser
http://192.168.8.139:8080

root@DockerSRV:~# docker stop my-nginx

root@DockerSRV:~# docker rm my-nginx

root@DockerSRV:~# docker search ubuntu


NAME DESCRIPTION
STARS OFFICIAL AUTOMATED
ubuntu Ubuntu is a Debian-based Linux
operating sys… 17514 [OK]
ubuntu/nginx Nginx, a high-performance reverse
proxy & we… 128
ubuntu/squid Squid is a caching proxy for the
Web. Long-t… 108
ubuntu/bind9 BIND 9 is a very flexible, full-
featured DNS… 101
ubuntu/apache2 Apache, a secure & extensible
open-source HT… 90
ubuntu/prometheus Prometheus is a systems and
service monitori… 70
ubuntu/mysql MySQL open source fast, stable,
multi-thread… 67

docker pull ubuntu/bind9


root@DockerSRV:~# docker run --name my-bind9 -d ubuntu/bind9
d584667fdfbcd58fd455a9eccf6228eebcf124c3045faa2c164b996bafb36d59

root@DockerSRV:~# docker exec -it my-bind9 /bin/bash


root@DockerSRV:~# docker stop my-bind9

root@DockerSRV:~# docker search apache2


NAME DESCRIPTION
STARS OFFICIAL AUTOMATED
ubuntu/apache2 Apache, a secure & extensible open-
source HT… 90
teamrock/apache2 TeamRock's Apache2
8 [OK]
kstaken/apache2 This a small Apache2 build that can be
exten… 3
prometsource/apache2
1

DOCKER COMPOSE

menampilkan index dari file php

mkdir apache-docker && cd apache-docker

root@DockerSRV:~/apache-docker# touch docker-compose.yml


root@DockerSRV:~/apache-docker# touch index.php
root@DockerSRV:~/apache-docker# touch Dockerfile

root@DockerSRV:~/apache-docker# tree ../apache-docker/


../apache-docker/
├── docker-compose.yml
├── Dockerfile
└── index.php

root@DockerSRV:~/apache-docker# vim.tiny index.php

<?php
echo "Hallo, saya dari " . gethostname();
?>

root@DockerSRV:~/apache-docker# vim.tiny Dockerfile

FROM php:apache
COPY index.php /var/www/html/index.php

root@DockerSRV:~/apache-docker# vim.tiny docker-compose.yml

version: '3'
services:
web:
build: .
container_name: apache_server
ports:
- "8080:80"

root@DockerSRV:~/apache-docker# docker-compose up -d

Creating network "apache-docker_default" with the default driver


Building web
Sending build context to Docker daemon 4.096kB
Step 1/2 : FROM php:apache
apache: Pulling from library/php
6e909acdb790: Already exists
a843a84fd431: Pull complete
54df264c65c0: Pull complete
e78f4a695473: Pull complete
dc325eebd405: Pull complete
b9e2f83d4e30: Pull complete
f01400cc6ea2: Pull complete
19883a5b6404: Pull complete
d49a5d4d78e5: Pull complete
9be9496ea2d8: Pull complete
dce5011ff25f: Pull complete
51cb2ba39d1e: Pull complete
7d6f3098fbfc: Pull complete
4f4fb700ef54: Pull complete
Digest:
sha256:4e4d213d34087fc762691319c0a6394c5a407d36fe6e2f107d033f8d441
d6252
Status: Downloaded newer image for php:apache
---> a32aa62d4c04
Step 2/2 : COPY index.php /var/www/html/index.php
---> 56f3351dce28
Successfully built 56f3351dce28
Successfully tagged apache-docker_web:latest
WARNING: Image for service web was built because it did not
already exist. To rebuild this image you must use `docker-compose
build` or `docker-compose up --build`.
Creating apache_server ... done

DOCKER VOLUME

docker volume create my_volume

docker volume ls

root@DockerSRV:~# docker volume inspect my_volume


[
{
"CreatedAt": "2025-03-24T18:39:13+07:00",
"Driver": "local",
"Labels": {},
"Mountpoint": "/var/lib/docker/volumes/my_volume/_data",
"Name": "my_volume",
"Options": {},
"Scope": "local"
}
]

root@DockerSRV:~# docker run -d --name my-nginx -v my_volume:/data


nginx
69593df5a4b917364f35bbb439ffd3e01aa34f19018ec636efed35c4b767e471

root@DockerSRV:~# docker stop my-nginx


my-nginx
root@DockerSRV:~# docker rm my-nginx
my-nginx
root@DockerSRV:~# docker volume rm my_volume
my_volume
root@DockerSRV:~# docker volume prune
WARNING! This will remove all local volumes not used by at least
one container.
Are you sure you want to continue? [y/N] y
Deleted Volumes:
8345e63125b96abe8f48b27855d45ec084aadd1483fef59e81ad764b7196710f
919a23a9618845eb44d771eeff64a93b82aee25d040818bb01eb59e924790511

Total reclaimed space: 0B

root@DockerSRV:~# docker run -d --name my-nginx -v /etc/:/data


nginx
efa20e94694737dbd4a748084bdb84ec21eaca685730807ea55befc012edeb07

root@DockerSRV:~# docker exec -it my-nginx /bin/bash


root@efa20e946947:/# ls /data/
PackageKit bluetooth default
grub.d kernel magic networks
rc0.d sgml sysctl.conf
X11 ca-certificates deluser.conf
gshadow kernel-img.conf magic.mime nftables.conf

Docker Volume dengan docker-compose

root@DockerSRV:~# mkdir volume-nginx


root@DockerSRV:~# cd volume-nginx/
root@DockerSRV:~/volume-nginx# vim.tiny docker-compose.yml
version: '3'
services:
app:
image: nginx
volumes:
- my_volume:/data

volumes:
my_volume:

root@DockerSRV:~/volume-nginx# docker-compose up -d
Creating network "volume-nginx_default" with the default driver
Creating volume "volume-nginx_my_volume" with default driver
Creating volume-nginx_app_1 ... done

root@DockerSRV:~/volume-nginx# docker volume inspect volume-


nginx_my_volume
[
{
"CreatedAt": "2025-03-24T18:54:46+07:00",
"Driver": "local",
"Labels": {
"com.docker.compose.project": "volume-nginx",
"com.docker.compose.version": "1.29.2",
"com.docker.compose.volume": "my_volume"
},
"Mountpoint": "/var/lib/docker/volumes/volume-
nginx_my_volume/_data",
"Name": "volume-nginx_my_volume",
"Options": null,
"Scope": "local"
}
]

You might also like