Github上的一个小项目
git clone <https://github.com/dockersamples/linux_tweet_app>
https://hub.docker.com/注册Docker,用户名就是Docker ID
栗子: 运行一个mysql 容器
docker container run \ --detach \ --name mydb \ -e MYSQL_ROOT_PASSWORD=12345 \ mysql:latest用户名是 root,密码是 12345
docker exec -it mydb \ mysql --user=root --password=$MYSQL_ROOT_PASSWORD --version查看Mysql容器中的mysql版本
Dockerfile的内容
FROM nginx:latest
COPY index.html /usr/share/nginx/html
COPY linux.png /usr/share/nginx/html
EXPOSE 80 443
CMD ["nginx", "-g", "daemon off;"]
基础镜像:nginx:latest 暴露端口:80、443
使用Dockerfile创建Image: docker image build --tag $DOCKERID/linux_tweet_app:1.0 . (末尾有个点,$DOCKEROD 是用户的Dockerhub用户名)
运行该镜像
docker container run \
--detach \
--publish 80:80 \
--name linux_tweet_app \
$DOCKERID/linux_tweet_app:1.0 # --detach 缩写 -d,--public缩写 -p(服务器:容器)
不关闭强制删除(包括了关闭),建议先
stop再rm
docker container rm --force linux_tweet_app
栗子:
docker container run \
-d \
-p 80:80 \
--name linux_tweet_app \
--mount type=bind,source="$(pwd)",target=/usr/share/nginx/html \
$DOCKERID/linux_tweet_app:1.0