docker命令用法

docker run -d -p 80:5000 training/webapp python app.py

-d 在后台中运行容器

-p 端口映射 容器中的5000端口映射到本机的80端口

training/webapp为镜像名

剩余的参数组成在容器内部运行的命令,python app.py 命令启动这个应用

docker run -t -i ubuntu /bin/bash

ubuntu 是你想运行的image

-t 标志, 在新容器中分配一个终端

-i 标志,允许和容器的标准输入有一个交互性的连接

/bin/bash 在容器内部发起一个 Bash shell


docker run -v /home/tiantao:/data ubuntu ls /data 

主机的/home/tiantao和docker中的目录/data 建立map 关系。任何在/home/tiantao 中的操作,都可以在docker中通过 ls /data下面看到

docker run -t -i -d -p 6379:6379 --name redis redis /usr/local/redis/bin/redis-server 

--name唯一标识


拉取仓库的centos
docker pull centos 
docker run -i -t --name redis centos /bin/bash
安装#redis
wget http://download.redis.io/releases/redis-3.2.9.tar.gz
tar -xvzf redis-3.2.9.tar.gz
cd redis-3.2.9
make PREFIX=/usr/local/redis install
cd /usr/local/redis/bin
redis-server &
退出 
ctrl+p  ctrl+q
#生成redis镜像
docker commit hash redis
#停止容器
docker stop hash/name
#开始容器
docker start hash/name
#生成以redis为基础新的容器
docker run -i -t redis  /bin/bash
docker run -i -t  centos /bin/bash  
wget -c https://nginx.org/download/nginx-1.12.1.tar.gz 
tar -zxvf nginx-1.12.1.tar.gz  
cd  nginx-1.12.1  
./configure
make
make install

cd /usr/local/nginx/sbin/
./nginx 
./nginx -s stop
./nginx -s reload

ps aux | grep nginx

开机自启动
vi /etc/rc.local
/usr/local/nginx/sbin/nginx

docker run -i -t -p 10001:80 -v /diska/docker/nginx/conf/:/usr/local/nginx/conf/ -v /diska/docker/nginx/wwwroot/:/usr/local/nginx/html/ nginx /usr/sbin/init

docker run -i -t  centos /bin/bash  

下载依赖
http://archive.apache.org/dist/apr/  
https://archive.apache.org/dist/httpd/
http://archive.apache.org/dist/apr/apr-1.5.2.tar.gz
http://archive.apache.org/dist/apr/apr-util-1.5.4.tar.gz
下载apache
https://archive.apache.org/dist/httpd/httpd-2.4.9.tar.gz

编译安装apr
tar -zxvf apr-1.5.2.tar.gz
cd apr-1.4.6
./configure --prefix=/usr/local/apr      #安装在/usr/local/下 命名为apr
make
make install

编译安装apr-util
tar -zxvf apr-util-1.5.4.tar.gz
cd apr-util-1.5.2
 ./configure --prefix=/usr/local/apr-util --with-apr=/usr/local/apr
make
make install

yum -y install pcre-devel

编译安装apache
./configure --prefix=/usr/local/apache --sysconfdir=/etc/httpd --enable-so --enable-rewirte --enable-ssl --enable-cgi --enable-cgid --enable-modules=most --enable-mods-shared=most --enable-mpms-shared=all --with-apr=/usr/local/apr --with-apr-util=/usr/local/apr-util


找到#ServerName www.example.com:80这行,去掉前面的#号,修改如下:
ServerName localhost:80 或者
ServerName 127.0.0.1:80

启动
/usr/local/apache/bin/apachectl restart

退出
ctrl+D

生成httpd镜像
docker commit hash httpd
  
运行httpd容器  
docker run -i -t -p 10002:80 httpd 

#nginx 负载
upstream  mytest {  
    server 119.27.166.108:10002 ;  
    server 119.27.166.108:10003;  
}  

server {  
    listen       80;  
    server_name  localhost;  
    location / {  
        proxy_pass   http://mytest;    #在这里设置一个代理,和upstream的名字一样  
    }  
}

做成系统服务参考https://www.cnblogs.com/piscesLoveCc/p/5867900.html
在做成系统服务时会报错Failed to get D-Bus connection: Operation not permitted
运行容器
docker run  --privileged -d -p 10001:80  -v /diska/docker/nginx/conf/:/usr/local/nginx/conf/ 
-v /diska/docker/nginx/wwwroot/:/usr/local/nginx/html/ nginx /usr/sbin/init
进入容器
docker exec -ti hash  bash 

apache设置成开机自动启动服务
vi /lib/systemd/system/httpd.service

[Unit]
Description=httpd
After=network.target
  
[Service]
Type=forking
ExecStart=/usr/local/apache/bin/apachectl start
ExecReload=/usr/local/apache/bin/apachectl reload
ExecStop=/usr/local/apache/bin/apachectl stop
PrivateTmp=true
  
[Install]
WantedBy=multi-user.target

设置开机启动
systemctl enable httpd.service
启动httpd服务
systemctl start httpd.service 
停止开机自启动
systemctl disable httpd.service
停止httpd服务
systemctl stop httpd.service 
重启httpd服务
systemctl restart httpd.service 

redis开机自启
https://blog.csdn.net/chwshuang/article/details/68489968

vi /etc/systemd/system/redis.service

[Unit]
Description=Redis
After=network.target

[Service]
ExecStart=/usr/local/bin/redis-server /usr/local/redis/redis.conf  --daemonize no
ExecStop=/usr/local/bin/redis-cli -h 127.0.0.1 -p 6379 shutdown

[Install]
WantedBy=multi-user.target

创建软链接是为了下一步系统初始化时自动启动服务
ln -s /lib/systemd/system/redis.service /etc/systemd/system/multi-user.target.wants/redis.service


systemctl daemon-reload
设置开机启动
systemctl enable redis.service
启动httpd服务
systemctl start redis.service
停止开机自启动
systemctl disable redis.service
停止httpd服务
systemctl stop redis.service 


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值