如果是linux系统,安装docker-ce可参考:
https://mirror.tuna.tsinghua.edu.cn/help/docker-ce/
配置国内镜像:
查询官方镜像内容,查看镜像的详细信息:
https://hub.docker.com/search?q=alpine&type=image
测试hello-world:
docker run hello-world
#查看版本:
docker version
#查看正在运行的镜像:
docker ps
#查看镜像日志
docker logs
#查看详细信息,镜像地址
docker info
#查看已经安装的镜像
docker images
#运行命令
docker run
-d:后台运行
-it:命令行交互
-p:端口映射
docker run -it alpine sh
配置alpine的国内镜像源:
#阿里云
sed -i 's/dl-cdn.alpinelinux.org/mirrors.aliyun.com/g' /etc/apk/repositories
#科大镜像源:
sed -i 's/dl-cdn.alpinelinux.org/mirrors.ustc.edu.cn/g' /etc/apk/repositories
#安装vim
apk --update add vim
apk是alpine下面管理包的命令,相关命令:
/ # apk -h
apk-tools 2.10.1, compiled for x86_64.
Installing and removing packages:
add Add PACKAGEs to 'world' and install (or upgrade) them, while ensuring that all dependencies are met
del Remove PACKAGEs from 'world' and uninstall them
System maintenance:
fix Repair package or upgrade it without modifying main dependencies
update Update repository indexes from all remote repositories
upgrade Upgrade currently installed packages to match repositories
cache Download missing PACKAGEs to cache and/or delete unneeded files from cache
Querying information about packages:
info Give detailed information about PACKAGEs or repositories
list List packages by PATTERN and other criteria
dot Generate graphviz graphs
policy Show repository policy for packages
Repository maintenance:
index Create repository index file from FILEs
fetch Download PACKAGEs from global repositories to a local directory
verify Verify package integrity and signature
manifest Show checksums of package contents
Use apk --help for command-specific help.
Use apk --help --verbose for a full command listing.
This apk has coffee making abilities.
/ #
官方文档:
https://docs.docker.com/docker-for-windows/?utm_source=docker4win_17.06.0-ce-win19&utm_medium=docs&utm_campaign=referral
docker pull mariadb/server:10.3
制定映射端口,root密码,还有别名(可用来起停、重启等操作):
docker run --name mariadbtest -e MYSQL_ROOT_PASSWORD=mypass -d -p 3307:3307 mariadb/server:10.3
启动、停止、重新启动:
docker start mariadbtest
docker stop mariadbtest
docker restart mariadbtest
删除所有容器和镜像的命令:
docker rm `docker ps -a |awk '{print $1}' | grep [0-9a-z]` 删除停止的容器
docker rmi $(docker images | awk '/^/ { print $3 }')
查看mariadb分配的IP地址:
docker inspect --format {{.NetworkSettings.IPAddress}} mariadbtest
docker exec -it mariadb bash
#删除容器,镜像还在,容器都是镜像的实例:
docker rm mariadbtest
#删除docker为mariadb创建的文件数据等
docker rm -v mariadbtest
linux下面有可能不能使用stop或者restart命令,需要执行以下命令:
sudo apt-get purge --auto-remove apparmor
sudo service docker restart
docker system prune --all --volumes
https://mariadb.com/kb/en/library/installing-and-using-mariadb-via-docker/
所有命令:
C:\Users\admin>docker
Usage: docker COMMAND
A self-sufficient runtime for containers
Options:
--config string Location of client config files (default
"C:\Users\admin\.docker")
-D, --debug Enable debug mode
--help Print usage
-H, --host list Daemon socket(s) to connect to
-l, --log-level string Set the logging level
("debug"|"info"|"warn"|"error"|"fatal")
(default "info")
--tls Use TLS; implied by --tlsverify
--tlscacert string Trust certs signed only by this CA (default
"C:\Users\admin\.docker\ca.pem")
--tlscert string Path to TLS certificate file (default
"C:\Users\admin\.docker\cert.pem")
--tlskey string Path to TLS key file (default
"C:\Users\admin\.docker\key.pem")
--tlsverify Use TLS and verify the remote
-v, --version Print version information and quit
Management Commands:
checkpoint Manage checkpoints
config Manage Docker configs
container Manage containers
image Manage images
network Manage networks
node Manage Swarm nodes
plugin Manage plugins
secret Manage Docker secrets
service Manage services
stack Manage Docker stacks
swarm Manage Swarm
system Manage Docker
volume Manage volumes
Commands:
attach Attach local standard input, output, and error streams to a running container
build Build an image from a Dockerfile
commit Create a new image from a container's changes
cp Copy files/folders between a container and the local filesystem
create Create a new container
deploy Deploy a new stack or update an existing stack
diff Inspect changes to files or directories on a container's filesystem
events Get real time events from the server
exec Run a command in a running container
export Export a container's filesystem as a tar archive
history Show the history of an image
images List images
import Import the contents from a tarball to create a filesystem image
info Display system-wide information
inspect Return low-level information on Docker objects
kill Kill one or more running containers
load Load an image from a tar archive or STDIN
login Log in to a Docker registry
logout Log out from a Docker registry
logs Fetch the logs of a container
pause Pause all processes within one or more containers
port List port mappings or a specific mapping for the container
ps List containers
pull Pull an image or a repository from a registry
push Push an image or a repository to a registry
rename Rename a container
restart Restart one or more containers
rm Remove one or more containers
rmi Remove one or more images
run Run a command in a new container
save Save one or more images to a tar archive (streamed to STDOUT by default)
search Search the Docker Hub for images
start Start one or more stopped containers
stats Display a live stream of container(s) resource usage statistics
stop Stop one or more running containers
tag Create a tag TARGET_IMAGE that refers to SOURCE_IMAGE
top Display the running processes of a container
unpause Unpause all processes within one or more containers
update Update configuration of one or more containers
version Show the Docker version information
wait Block until one or more containers stop, then print their exit codes
Run 'docker COMMAND --help' for more information on a command.
删除已经退出的容器:
windows下面:
You could create a batch (.bat) file with these commands in it:
@ECHO OFF
FOR /f "tokens=*" %%i IN ('docker ps -q') DO docker stop %%i
If you want to run this command directly in the console, replace %%i with %i, like:
FOR /f "tokens=*" %i IN ('docker ps -q') DO docker stop %i
In Git Bash or Bash for Windows you could run:
docker stop $(docker ps -q)
参考:https://stackoverflow.com/questions/48813286/stop-all-docker-containers-at-once-on-windows
官方入门:
https://github.com/docker/labs/tree/master/beginner
laravel开发环境:
https://github.com/laradock/laradock
http://laradock.io/
美团容器架构:
https://tech.meituan.com/2018/11/15/docker-architecture-and-evolution-practice.html
https://tech.meituan.com/tags/docker.html