拉取鏡像:docker pull xxx
啓動鏡像:docker run --name xxx 8080:8080 -d xxx
查看容器:docker ps xxx 中止容器:docker stop xxx 啓動容器:docker start xxx 刪除容器:docker rm xxx
進入容器控制檯:docker exec -it xxx bash
拷貝容器中文件到宿主機:docker cp xxx:/usr/local/tomcat/conf/server.xml /usr/local/docker/tomcat/conf
拷貝宿主機文件到容器:docker cp /usr/local/docker/tomcat/conf/server.xml xxx:/usr/local/tomcat/conf
更改docker源:https://cr.console.aliyun.com/undefined/instances/mirrors
docker pull nginx docker run --name nginx -p 80:80 -d nginx mkdir -p /usr/local/docker/nginx/www /usr/local/docker/nginx/conf /usr/local/docker/nginx/logs docker cp ${container-id}:/etc/nginx/nginx.conf /usr/local/docker/nginx/conf docker stop nginx docker rm nginx docker run -d -p 80:80 --net host --name nginx -v /usr/local/docker/nginx/www:/usr/share/nginx/html -v /usr/local/docker/nginx/conf/nginx.conf:/etc/nginx/nginx.conf -v /usr/local/docker/nginx/logs:/var/log/nginx nginx
docker pull redis mkdir -p /usr/local/docker/redis/conf /usr/local/docker/redis/data docker run -p 6379:6379 --name redis -v /usr/local/docker/redis/conf:/etc/redis/redis.conf -v /usr/local/docker/redis/data:/data -d redis redis-server /etc/redis/redis.conf --appendonly yes
docker run -p 6379:6379 --name redis -v /usr/local/redis/etc/redis.conf:/etc/redis/redis.conf -d redis redis-server --appendonly yes # /usr/local/docker/redis/conf掛載到/etc/redis/redis.conf # /usr/local/docker/redis/data掛載到/data # --appendonly yes 開啓持久化
1.新建Dockerfile
在/usr/local/docker/jenkins下html
touch Dockerfile
vi Dockerfile
2.加入如下內容:mysql
FROM jenkins USER root #清除了基礎鏡像設置的源,切換成騰訊雲的jessie源 #使用非騰訊雲環境的須要將 tencentyun 改成 aliyun #RUN echo '' > /etc/apt/sources.list.d/jessie-backports.list \ # && echo "deb http://mirrors.aliyun.com/debian jessie main contrib non-free" > /etc/apt/sources.list \ # && echo "deb http://mirrors.aliyun.com/debian jessie-updates main contrib non-free" >> /etc/apt/sources.list \ # && echo "deb http://mirrors.aliyun.com/debian-security jessie/updates main contrib non-free" >> /etc/apt/sources.list #更新源並安裝缺乏的包 RUN apt-get update && apt-get install -y libltdl7 && apt-get update ARG dockerGid=999 RUN echo "docker:x:${dockerGid}:jenkins" >> /etc/group # 安裝 docker-compose 由於等下構建環境的須要 RUN curl -L https://github.com/docker/compose/releases/download/1.16.1/docker-compose-`uname -s`-`uname -m` -o /usr/local/bin/docker-compose RUN chmod +x /usr/local/bin/docker-compose
3.構建nginx
docker build . -t jenkins
4.在啓動Jenkins時,須要先建立一個Jenkins的配置目錄,而且掛載到docker 裏的Jenkins目錄下git
mkdir -p /var/jenkins_home
5.修改目錄權限(很重要!)github
chown -R 1000 /var/jenkins_home
6.運行 Jenkinsweb
docker run --name jenkins -p 8080:8080 -p 50000:50000 \ -v /var/run/docker.sock:/var/run/docker.sock \ -v $(which docker):/bin/docker \ -v /var/jenkins_home:/var/jenkins_home \ -d jenkins
7.進入容器redis
docker exec -it jenkins /bin/bash
8.查看密碼sql
cat /var/jenkins_home/secrets/initialAdminPassword
docker run --name tomcat -p 8079:8079 -v /usr/local/docker/tomcat/webapps:/usr/local/tomcat/webapps -v /usr/local/docker/tomcat/conf/server.xml:/usr/local/tomcat/conf/server.xml -d tomcat docker exec -it tomcat bash //進入控制檯
docker pull rabbitmq:3.7-management docker run -d --name rabbitmq -p 5672:5672 -p 15672:15672 -v `pwd`/data:/var/lib/rabbitmq --hostname myRabbit -e RABBITMQ_DEFAULT_USER=admin -e RABBITMQ_DEFAULT_PASS=admin rabbitmq:3.7-management
#rabbitmq命令 rabbitmqctl list_users rabbitmqctl add_user username password rabbitmqctl set_user_tags username administrator(角色分爲:none、management、policymaker、monitoring、administrator) rabbitmqctl change_password userName newPassword rabbitmqctl delete_user username
docker pull elasticsearch:6.8.0 docker run -d -e ES_JAVA_OPTS="-Xms512m -Xmx512m" -p 9200:9200 -p 9300:9300 --name elasticsearch elasticsearch:6.8.0 #安裝插件 docker exec -it xxxxx /bin/bash cd /usr/share/elasticsearch/bin plugin install mobz/elasticsearch-head
docker pull mysql:5.7 docker run -itd -p 3306:3306 --name mysql -v /e/xxx/mysql/data:/var/lib/mysql -e MYSQL_ROOT_PASSWORD=123456 --privileged=true mysql:5.7
#docker中 啓動全部的容器命令 docker start $(docker ps -a | awk '{ print $1}' | tail -n +2) #docker中 關閉全部的容器命令 docker stop $(docker ps -a | awk '{ print $1}' | tail -n +2) docker中 刪除全部的容器命令 #docker rm $(docker ps -a | awk '{ print $1}' | tail -n +2) docker中 刪除全部的鏡像 docker rmi $(docker images | awk '{print $3}' |tail -n +2) #tail -n +2 表示從第二行開始讀取
來源:docker
菜鳥教程tomcat