第一部分:ubuntu系统安装docker
先保证系统的网络是通的
apt install docker.io 远程下载安装docker
systemctl start docker 系统启动docker
systemctl enable docker 使能docker
docker version 查看docker版本
第二部分:docker的基本使用
1、docker search ubuntu 搜索镜像
root@ubuntu:/home# docker search ubuntu
NAME DESCRIPTION STARS OFFICIAL AUTOMATED
ubuntu Ubuntu is a Debian-based Linux operating sys… 13959 [OK]
websphere-liberty WebSphere Liberty multi-architecture images … 283 [OK]
ubuntu-upstart DEPRECATED, as is Upstart (find other proces… 112 [OK]
neurodebian NeuroDebian provides neuroscience research s… 88 [OK]
open-liberty Open Liberty multi-architecture images based… 51 [OK]
ubuntu-debootstrap DEPRECATED; use "ubuntu" instead 46 [OK]
ubuntu/nginx Nginx, a high-performance reverse proxy & we… 37
ubuntu/mysql MySQL open source fast, stable, multi-thread… 28
ubuntu/apache2 Apache, a secure & extensible open-source HT… 26
ubuntu/prometheus Prometheus is a systems and service monitori… 22
kasmweb/ubuntu-bionic-desktop Ubuntu productivity desktop for Kasm Workspa… 21
ubuntu/squid Squid is a caching proxy for the Web. Long-t… 15
ubuntu/postgres PostgreSQL is an open source object-relation… 15
ubuntu/bind9 BIND 9 is a very flexible, full-featured DNS… 13
ubuntu/redis Redis, an open source key-value store. Long-… 9
ubuntu/grafana Grafana, a feature rich metrics dashboard & … 5
ubuntu/prometheus-alertmanager Alertmanager handles client alerts from Prom… 5
ubuntu/memcached Memcached, in-memory keyvalue store for smal… 4
ubuntu/telegraf Telegraf collects, processes, aggregates & w… 3
circleci/ubuntu-server This image is for internal use 3
ubuntu/cortex Cortex provides storage for Prometheus. Long… 2
ubuntu/cassandra Cassandra, an open source NoSQL distributed … 1
bitnami/ubuntu-base-buildpack Ubuntu base compilation image 0 [OK]
snyk/ubuntu A base ubuntu image for all broker clients t… 0
rancher/ubuntuconsole 0
root@ubuntu:/home#
docker pull ubuntu 拉取镜像
root@ubuntu:/home# docker pull ubuntu
Using default tag: latest
latest: Pulling from library/ubuntu
Digest: sha256:bea6d19168bbfd6af8d77c2cc3c572114eb5d113e6f422573c93cb605a0e2ffb
Status: Image is up to date for ubuntu:latest
docker.io/library/ubuntu:latest
2、docker images 查看有哪些镜像
root@ubuntu:/home# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
ubuntu 20.04 ff0fea8310f3 12 days ago 72.8MB
ubuntu latest ff0fea8310f3 12 days ago 72.8MB
hello-world latest feb5d9fea6a5 6 months ago 13.3kB
ubuntu 14.04 13b66b487594 12 months ago 197MB
root@ubuntu:/home#
docker create ubuntu:20.04 ubuntu:20.04是 docker images显示的信息,20.04是版本号
root@ubuntu:/home# docker create ubuntu:20.04
39f99c62e192b526ccbac079662a9efe2de2b210b003cbffe6531128be3c8cf2
root@ubuntu:/home#
docker run -i -t ubuntu:20.04 /bin/bash 运行容器,并在容器中运行程序bash,然后敲exit就能退出bash程序
root@ubuntu:/home# docker run -i -t ubuntu:20.04 /bin/bash
root@f5bb622297f7:/# exit
exit
root@ubuntu:/home#
docker ps 查看当前容器
docker ps -a 查看当前所有容器
root@ubuntu:/home# docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
277a8bc922a4 ubuntu:20.04 "/bin/bash" 5 minutes ago Exited (0) 5 minutes ago optimistic_williams
3、docker exec -i -t NAME ContainerID 访问正在容器中运行的应用,NAME是docker ps看到的name,ContainerID是其中的COMMAND
docker start NAME/ContainerID 一般使用ContainerID
root@ubuntu:/home# docker start 277a8bc922a4
277a8bc922a4
docker attach ContainerID 后台登录到容器的应用中,一般情况是一个容器一个应用
root@ubuntu:/home# docker attach 277a8bc922a4
root@277a8bc922a4:/# exit
exit
root@ubuntu:/home#
docker restart NAME/ContainerID
docker stop NAME/ContainerID
docker rm NAME/ContainerID
docker rmi image_name 删除镜像
以上仅仅是在docker容器中启bash应用
下一篇转载阮一峰大神的docker操作demo,自己编译应用并在docker中运行。