docker 安装、使用以及nginx使用笔记

docker 安装、使用以及nginx使用笔记

springboot 使用docker插件配置pom.xml。运行 mvn package 后则自动推送到远程docker镜像中

<!-- docker 插件-->
 <plugin>
                <groupId>com.spotify</groupId>
                <artifactId>docker-maven-plugin</artifactId>
                <version>1.1.0</version>
                <executions>
                    <execution>
                        <id>build-image</id>
                        <phase>package</phase>
                        <goals>
                            <goal>build</goal>
                        </goals>
                    </execution>
                </executions>
                <configuration>
                    <imageName>mall-tiny/${project.artifactId}:${project.version}</imageName>
                    <dockerHost>http://192.168.1.109:2375</dockerHost>
                    <baseImage>java:8</baseImage>
                    <entryPoint>["java", "-jar","/${project.build.finalName}.jar"]
                    </entryPoint>
                    <resources>
                        <resource>
                            <targetPath>/</targetPath>
                            <directory>${project.build.directory}</directory>
                            <include>${project.build.finalName}.jar</include>
                        </resource>
                    </resources>
                </configuration>
            </plugin>

Linux 安装docker

  1. 安装依赖:
yum install -y yum-utils \
   	  device-mapper-persistent-data \
   	  lvm2
  1. 设置仓库
yum-config-manager \
   		--add-repo \
   		https://download.docker.com/linux/centos/docker-ce.repo
  1. 安装docker
yum install docker-ce docker-ce-cli containerd.io

注意: 如果安装失败 报错(but none of the providers can be installed)
解决方法:

 yum list docker-ce --showduplicates | sort -r    //检查相应的软件包版本
   		 yum -y install  docker-ce-18.06.0.ce-3.el7     //安装低版本的软件包
   		 wget https://download.docker.com/linux/centos/7/x86_64/edge/Packages/containerd.io-1.2.6-3.3.el7.x86_64.rpm    //下载相关软件包
   		 yum -y install containerd.io-1.2.6-3.3.el7.x86_64.rpm    //升级containerd.io软件包   如果在此过程中安装失败再重新执行这个命令即可有可能是网络问题

安装完成后重新安装Docker

yum -y install docker-ce    //安装Docker软件包

安装完成后启动Docker

[root@localhost ~]# systemctl  start docker      //启动并加入开机启动
   						systemctl enable docker

    [root@localhost ~]#server  docker start        //CentOS6启动方法 

开启docker 远程 服务

开启docker 2375 防火墙端口   firewall-cmd --zone=public -add-port=2375/tcp --permanent
        防火墙开放添加8080端口     firewall-cmd --zone=public --add-port=8080/tcp --permanent
        刷新防火墙:firewall-cmd --reload
		重新启动防火墙        		systemctl restart firewalld.service
		查看端口是否打开            firewall-cmd --zone= public --query-port=2375/tcp
	浏览器访问IP:2375/info 则看到信息说明配置成功。
	
浏览器访问    http://192.168.1.109:2375/info
	
ID	"Q3K7:NW7J:LDMW:TSKZ:5FO7:GHPS:2PTC:VF2S:NTSU:KCMT:TD5K:3JPY"
Containers	0
ContainersRunning	0
ContainersPaused	0
ContainersStopped	0
Images	3
Driver	"overlay2"
DriverStatus	
0	
0	"Backing Filesystem"
1	"xfs"
1	
0	"Supports d_type"
1	"true"
2	
0	"Native Overlay Diff"
1	"true"
SystemStatus	null
Plugins	
Volume	
0	"local"
Network	
0	"bridge"
1	"host"
2	"ipvlan"
3	"macvlan"
4	"null"
5	"overlay"
Authorization	null
Log	
0	"awslogs"
1	"fluentd"
2	"gcplogs"
3	"gelf"
4	"journald"
5	"json-file"
6	"local"
7	"logentries"
8	"splunk"
9	"syslog"
MemoryLimit	true
SwapLimit	true
KernelMemory	true
KernelMemoryTCP	true
CpuCfsPeriod	true
CpuCfsQuota	true
CPUShares	true
CPUSet	true
PidsLimit	true
IPv4Forwarding	true
BridgeNfIptables	true
BridgeNfIp6tables	true
Debug	false
NFd	27
OomKillDisable	true
NGoroutines	40
SystemTime	"2020-07-13T04:41:35.17729393-04:00"
LoggingDriver	"json-file"
CgroupDriver	"cgroupfs"
NEventsListener	0
KernelVersion	"4.18.0-147.8.1.el8_1.x86_64"
OperatingSystem	"CentOS Linux 8 (Core)"
OSType	"linux"
Architecture	"x86_64"
IndexServerAddress	"https://index.docker.io/v1/"
RegistryConfig	
AllowNondistributableArtifactsCIDRs	[]
AllowNondistributableArtifactsHostnames	[]
InsecureRegistryCIDRs	
0	"127.0.0.0/8"
IndexConfigs	
docker.io	
Name	"docker.io"
Mirrors	
0	"https://6kx4zyno.mirror.aliyuncs.com/"
Secure	true
Official	true
Mirrors	
0	"https://6kx4zyno.mirror.aliyuncs.com/"
NCPU	1
MemTotal	835776512
GenericResources	null
DockerRootDir	"/var/lib/docker"
HttpProxy	""
HttpsProxy	""
NoProxy	""
Name	"localhost.localdomain"
Labels	[]
ExperimentalBuild	false
ServerVersion	"19.03.11"
ClusterStore	""
ClusterAdvertise	""
Runtimes	
runc	
path	"runc"
DefaultRuntime	"runc"
Swarm	
NodeID	""
NodeAddr	""
LocalNodeState	"inactive"
ControlAvailable	false
Error	""
RemoteManagers	null
LiveRestoreEnabled	false
Isolation	""
InitBinary	"docker-init"
ContainerdCommit	
ID	"894b81a4b802e4eb2a91d1ce216b8817763c29fb"
Expected	"894b81a4b802e4eb2a91d1ce216b8817763c29fb"
RuncCommit	
ID	"425e105d5a03fabd737a126ad93d62a9eeede87f"
Expected	"425e105d5a03fabd737a126ad93d62a9eeede87f"
InitCommit	
ID	"fec3683"
Expected	"fec3683"
SecurityOptions	
0	"name=seccomp,profile=default"
Warnings	
0	"WARNING: API is accessible on http://0.0.0.0:2375 without encryption.\n         Access to the remote API is equivalent to root access on the host. Refer\n         to the 'Docker daemon attack surface' section in the documentation for\n         more information: https://docs.docker.com/engine/security/security/#docker-daemon-attack-surface"

docker 使用

1、启动 docker

systemctl start docker

2、关闭docker

systemctl stop docker

3、查看docker的运行状态

        systemctl status docker
		
		docker images   // 查看docker镜像
		
		docker ps 		//查看docker容器

4、启动docker 容器

			docker start 容器名称

			或者 docker start 容器id

5、停止docker 容器

docker stop 容器名称

6、删除

查询服务 :docker ps
先停止 服务:docker stop xxx 
然后删除 服务:docker rm xxxx
在删除 镜像:docker rmi xxx

示例:

[root@localhost my.Shells]# docker images
REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE
docker.io/nginx     latest              3f8a4339aadd        3 weeks ago         108.5 MB
docker.io/redis     latest              1e70071f4af4        6 weeks ago         106.7 MB

[root@localhost my.Shells]# docker run -p 8080:80 -d docker.io/nginx  //将80端口映射为8080,或者80:80还是原先的80端口,不可以不写。
c0462d5e18783e20f9515108fa62ab0f2ac808ea85370a7c82aee9407abf4672
[root@localhost my.Shells]# netstat -anp | grep 8080  //端口已经开启了
tcp6       0      0 :::8080                 :::*                    LISTEN      2529/docker-proxy-c 
[root@localhost my.Shells]# docker ps  //nginx已经在运行了
CONTAINER ID        IMAGE               COMMAND                  CREATED             STATUS              PORTS                  NAMES
c0462d5e1878        docker.io/nginx     "nginx -g 'daemon off"   4 minutes ago       Up 4 minutes        0.0.0.0:8080->80/tcp   angry_mccarthy

nginx

    启动: service nginx start
	
	快速停止nginx:		nginx -s stop 
	
	重启 Nginx:   nginx -s reopen
	
	修改配置后重新加载生效: nginx -s reload

注意事项:
如果安装好nginx后无法通过浏览器来访问请按照下面的步骤逐一执行
首先检查

		nignx -t

		然后查看

		ps -ef | grep  nginx

		如果以上都没有问题那就是防火墙的问题

		sudo firewall-cmd --permanent --zone=public --add-service=http 
		sudo firewall-cmd --permanent --zone=public --add-service=https

		sudo firewall-cmd --reload

查看启动的进程: ps -ef | grep xxxx 
查看运行情况 :   netstat -tnlp

查考使用maven插件构建docker地址:https://www.imooc.com/article/details/id/290801

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值