[ Linux ] Docker Overview on Ubuntu24

Install Docker
sudo apt install docker.io
Check Docker Version
docker -v
Configure Mirror Sources
sudo touch /etc/docker/daemon.json
sudo nano /etc/docker/daemon.json
{
 "registry-mirrors": ["https://registry.docker-cn.com"],
 "insecure-registries": ["10.0.0.12:5000"]
}
Start Docker Service
sudo systemctl enable docker
sudo systemctl start docker
sudo systemctl stop docker
Load Docker Image

pull image from repository

sudo docker pull pengbai/docker-supermario

load image from file

sudo docker load -i supermario.tar

view all images

sudo docker images

save image to file

sudo docker save -o supermario.tar pengbai/docker-supermario

remove image

sudo docker rmi docker-supermario
Run Docker Image

create and run a docker instance, -d means run in background

sudo docker run -dit -d -p 10001:8080 --name supermario pengbai/docker-supermario

start a docker instance

sudo docker start supermario

view running docker instance

sudo docker ps -a

stop a docker instance

sudo docker stop supermario

remove a docker instance

sudo docker rm supermario

launch docker instance webpage

http://localhost:10001

run command line in docker instance

sudo docker run pengbai/docker-supermario /bin/echo "Hello world"

enter terminal in a docker instance

sudo docker exec -it supermario bash
Create Data Volume

create a data volume

sudo docker volume create supermario

list all data volume

sudo docker volume ls

view detail of specific data volume

sudo docker volume inspect supermario

remove specific data volume

sudo docker volume rm supermario

data under volume can be shared between multiple docker instances

sudo open /var/lib/docker/volumes/
Build and Publish Docker Image

create docker build script

sudo touch /home/easing/ubuntu24-dev/Dockerfile
sudo nano /home/easing/ubuntu24-dev/Dockerfile
FROM ubuntu:24.10
RUN apt-get update -y
RUN apt-get upgrade -y
RUN apt-get install -y curl
RUN useradd admin
RUN /bin/echo 'admin:123456' |chpasswd
RUN /bin/echo -e "LANG=\"en_US.UTF-8\"" >/etc/default/local
EXPOSE 8080

build docker image

sudo docker build -t byteflys/ubuntu24:dev /home/easing/ubuntu24-dev

list docker images

sudo docker images

create a docker container and enter command line terminal

sudo docker run -ti byteflys/ubuntu24:dev

check image data

id admin

exit command line

exit

rename image tag

sudo docker tag byteflys/ubuntu24:dev byteflys/ubuntu24:dev

register a docker io account

https://www.docker.com
sudo docker login

push image to docker hub repository

sudo docker push byteflys/ubuntu24:dev

visit your latest pushed image

https://hub.docker.com/repository/docker/byteflys/ubuntu24
Delete All Images and Volumes
sudo docker system prune -a -f --volumes
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值