Створюємо файл з ім'ям Dockerfile
наступного змісту, в даному прикладі ми створюємо образ під ansible
FROM ubuntu:20.04
RUN apt-get update && apt-get upgrade -y
RUN apt-get install software-properties-common -y
RUN add-apt-repository --yes --update ppa:ansible/ansible
RUN apt install ansible -y && apt install vim -y && apt install iputils-ping -y && rm -rf /var/lib/apt/lists/*
Для збирання з файлу образу:
docker build -t ansible:1.0 .
Приклад: docker-compose.yml
:
version: '3.8'
services:
ansible-ubuntu:
image: ansible-ubuntu:1.0
environment:
TZ: "Europe/Kiev"
# volumes:
# - ./scripts:/root/scripts
command: tail -f /dev/null
Для запуску використовувати команду, де:
-f
якщо потрібно вказати певний файл
--force-recreate
перед запуском перечитати конфігураційний файл
-d
запустити як демон
docker-compose -f docker-compose.yml up --force-recreate
Ще один приклад Dockerfile
FROM centos:7
ENV container docker
RUN (cd /lib/systemd/system/sysinit.target.wants/; for i in *; do [ $i == \
systemd-tmpfiles-setup.service ] || rm -f $i; done); \
rm -f /lib/systemd/system/multi-user.target.wants/*;\
rm -f /etc/systemd/system/*.wants/*;\
rm -f /lib/systemd/system/local-fs.target.wants/*; \
rm -f /lib/systemd/system/sockets.target.wants/*udev*; \
rm -f /lib/systemd/system/sockets.target.wants/*initctl*; \
rm -f /lib/systemd/system/basic.target.wants/*;\
rm -f /lib/systemd/system/anaconda.target.wants/*;
#VOLUME [ "/sys/fs/cgroup", "/tmp/$(mktemp -d)" ]
VOLUME [ "/sys/fs/cgroup:sys/fs/cgroup:ro", "/tmp/$(mktemp -d):/run" ]
## if you're using an Ubuntu host -v /tmp/$(mktemp -d):/run
## https://hub.docker.com/_/centos
RUN yum -y install httpd mod_ssl; yum clean all; systemctl enable httpd.service;
Складання:
docker build -t c7-httpd:1.0 .
Запуск із перезаписуваннямvolume
docker run -dit --name test-httpd -v /sys/fs/cgroup:/sys/fs/cgroup:ro -v /tmp/$(mktemp -d):/run -p 5555:80 c7-httpd:1.0
docker run --rm -it <имя_образа> /bin/bash
Відобразити cache docker system df
TYPE TOTAL ACTIVE SIZE RECLAIMABLE
Images 6 6 1.709GB 0B (0%)
Containers 6 6 1.595MB 0B (0%)
Local Volumes 1 1 634.2kB 0B (0%)
Build Cache 90 0 1.888GB 1.888GB
Видалення cache старіше 5 днів
docker system prune -f --filter "until=$((5 * 24))h"