美文网首页
如何通过docker自定义自己的开发环境

如何通过docker自定义自己的开发环境

作者: 张清柏 | 来源:发表于2020-07-27 17:10 被阅读0次
  • 下载ubuntu镜像,注意更新docker镜像源
    docker pull ubuntu:latest
  • 查看镜像,启动


    image.png
docker run -itd --name ubuntu-lnmp   ubuntu:latest
zhangguofu@bogon ~ % docker exec -it 52476 bash          
               
# 更改dns
root@c6016835fe82:/# cat /etc/hosts
127.0.0.1   localhost
::1 localhost ip6-localhost ip6-loopback
fe00::0 ip6-localnet
ff00::0 ip6-mcastprefix
ff02::1 ip6-allnodes
ff02::2 ip6-allrouters
172.17.0.2  c6016835fe82
nameserver 114.114.114.114
nameserver 8.8.8.8
  • 更新源 apt-get update
    apt-get update

  • 开始安装lnmp脚本
    wget http://soft.vpser.net/lnmp/lnmp1.7.tar.gz -cO lnmp1.7.tar.gz && tar zxf lnmp1.7.tar.gz && cd lnmp1.7 && ./install.sh lnmp

  • 可以安装redis什么的扩展,这个环境配置好了就行

  • 打包镜像
    docker commit -m "this is my first images" -a "guofu" c6016835fe82 ubunut_lnmp:v1

  • 打标签
    docker tag 682261384f44 ubuntu/lnmp:v1

  • 镜像上传

    • 如遇以下报错,请先退出登录,再登录一次
zhangguofu@bogon ~ % docker push ubuntu/lnmp:v1
The push refers to repository [docker.io/ubuntu/lnmp]
c89fc157a3ae: Preparing 
095624243293: Preparing 
a37e74863e72: Preparing 
8eeb4a14bcb4: Preparing 
ce3011290956: Preparing 
denied: requested access to the resource is denied


zhangguofu@bogon ~ % docker  logout
Removing login credentials for https://index.docker.io/v1/
zhangguofu@bogon ~ % docker  login 
Login with your Docker ID to push and pull images from Docker Hub. If you don't have a Docker ID, head over to https://hub.docker.com to create one.
Username: hongzhulei
Password: 
Error response from daemon: Get https://registry-1.docker.io/v2/: unauthorized: incorrect username or password
zhangguofu@bogon ~ % docker  login
Login with your Docker ID to push and pull images from Docker Hub. If you don't have a Docker ID, head over to https://hub.docker.com to create one.
Username: hongzhulei
Password: 
Login Succeeded
zhangguofu@bogon ~ % 
  • 上传镜像完毕,如果镜像上传有问题 参考
zhangguofu@bogon ~ % docker push ubunut_lnmp:v1
The push refers to repository [docker.io/library/ubunut_lnmp]
c89fc157a3ae: Preparing 
095624243293: Preparing 
a37e74863e72: Preparing 
8eeb4a14bcb4: Preparing 
ce3011290956: Preparing 
denied: requested access to the resource is denied
zhangguofu@bogon ~ % 
zhangguofu@bogon ~ % 
zhangguofu@bogon ~ % 
zhangguofu@bogon ~ % 
# 以下命令解释,镜像名  作者名(docker用户名)/tag 
zhangguofu@bogon ~ % docker tag ubunut_lnmp:v1  hongzhulei/ubunut_lnmp:v1
zhangguofu@bogon ~ % docker images
REPOSITORY               TAG                 IMAGE ID            CREATED             SIZE
hongzhulei/ubunut_lnmp   v1                  682261384f44        About an hour ago   4.01GB
ubunut_lnmp              v1                  682261384f44        About an hour ago   4.01GB
zhangguofu@bogon ~ % docker push hongzhulei/ubunut_lnmp:v1
The push refers to repository [docker.io/hongzhulei/ubunut_lnmp]
c89fc157a3ae: Pushing [=>                                                 ]  80.63MB/3.936GB
  • 根据镜像启动容器,挂载端口号
docker run -d -it -p 80:80 -p 13306:3360  --name lnmp_v2  -v ~/website:/home/wwwroot -v ~/nginx_conf:/usr/local/nginx/conf/vhost ubunut_lnmp:v1
  • 批量暴露端口
    docker run -d -it -p 80:80 -p 13306:3306 -p 9500-9700:9500-9700 -p 16379:6379 --name lnmp_v1 -v ~/website:/home/wwwroot -v ~/nginx_conf:/usr/local/nginx/conf/vhost ubunut_lnmp:v1

  • 进入容器启动lnmp,关于80端口,我们知道 web支持的http和https就是80 和443端口,本地的nginx ,就没用了,

相关文章

网友评论

      本文标题:如何通过docker自定义自己的开发环境

      本文链接:https://www.haomeiwen.com/subject/ddinlktx.html