docker容器部署

scadm 2021年5月9日12:09:50
评论
9061 3987字

查找镜像文件

# 在Docker官方仓库中搜索Nginx镜像,Nginx镜像文件中只包含Nginx软件程序、数据文件
[root@node1 src]# docker search nginx 
NAME                               DESCRIPTION                                     STARS               OFFICIAL            AUTOMATED
nginx                              Official build of Nginx.                        14587               [OK]                
jwilder/nginx-proxy                Automated Nginx reverse proxy for docker con…   1984                                    [OK]
richarvey/nginx-php-fpm            Container running Nginx + PHP-FPM capable of…   810                                     [OK]
jc21/nginx-proxy-manager           Docker container for managing Nginx proxy ho…   162                                     
linuxserver/nginx                  An Nginx container, brought to you by LinuxS…   143                                     
tiangolo/nginx-rtmp                Docker image with Nginx using the nginx-rtmp…   117                                     [OK]
jlesage/nginx-proxy-manager        Docker container for Nginx Proxy Manager        97                                      [OK]
bitnami/nginx                      Bitnami nginx Docker Image                      95                                      [OK]
alfg/nginx-rtmp                    NGINX, nginx-rtmp-module and FFmpeg from sou…   89                                      [OK]
jasonrivers/nginx-rtmp             Docker images to host RTMP streams using NGI…   88                                      [OK]
nginxdemos/hello                   NGINX webserver that serves a simple page co…   67                                      [OK]
privatebin/nginx-fpm-alpine        PrivateBin running on an Nginx, php-fpm & Al…   49                                      [OK]
nginx/nginx-ingress                NGINX Ingress Controller for Kubernetes         49                                      
nginxinc/nginx-unprivileged        Unprivileged NGINX Dockerfiles                  32                                      
schmunk42/nginx-redirect           A very simple container to redirect HTTP tra…   19                                      [OK]
staticfloat/nginx-certbot          Opinionated setup for automatic TLS certs lo…   19                                      [OK]
nginx/nginx-prometheus-exporter    NGINX Prometheus Exporter                       16                                      
centos/nginx-112-centos7           Platform for running nginx 1.12 or building …   15                                      
centos/nginx-18-centos7            Platform for running nginx 1.8 or building n…   13                                      
raulr/nginx-wordpress              Nginx front-end for the official wordpress:f…   13                                      [OK]
flashspys/nginx-static             Super Lightweight Nginx Image                   9                                       [OK]
mailu/nginx                        Mailu nginx frontend                            8                                       [OK]
bitnami/nginx-ingress-controller   Bitnami Docker Image for NGINX Ingress Contr…   8                                       [OK]
ansibleplaybookbundle/nginx-apb    An APB to deploy NGINX                          2                                       [OK]
wodby/nginx                        Generic nginx                                   1                                       [OK]

下载镜像

# 从Docker官方仓库中下载Nginx镜像,下载至Docker宿主机上特定目录下
1)docker load <nginx.tar
2)docker pull nginx

[root@node1 src]# docker pull nginx 
Using default tag: latest
latest: Pulling from library/nginx
6f28985ad184: Pull complete 
29f7ebf60efd: Pull complete 
879a7c160ac6: Pull complete 
de58cd48a671: Pull complete 
be704f37b5f4: Pull complete 
158aac73782c: Pull complete 
Digest: sha256:d2925188effb4ddca9f14f162d6fba9b5fab232028aa07ae5c1dab764dca8f9f
Status: Downloaded newer image for nginx:latest
docker.io/library/nginx:latest

查看已下载的或者导入的Nginx镜像文件的存储位置和列表信息

[root@node1 src]# ls /var/lib/docker/image/overlay2/
distribution  imagedb  layerdb  repositories.json

[root@node1 src]# docker images
REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE
nginx               latest              6084105296a9        5 days ago          133MB

[root@node1 src]# docker images|grep -aiwE nginx 
nginx               latest              6084105296a9        5 days ago          133MB

创建一台nginx容器

[root@node1 src]# docker run -itd -p 80:80 --name=scyun01 --privileged nginx:latest
86a654873eafd80594f067f40675d9d5404a4a14d2769cfbd9207cd8cbc17d18

	Run,全新创建并且启动一台新容器;
	-i,interactive打开交互模式;
	-t,tty打开登录终端;
	-d,detach后台启动;
	-p,publish发布端口,将宿主机80(第一个)映射至容器的80端口;(DNAT)

查看虚拟机(容器)状态 与 ip地址

[root@node1 src]# docker ps 
CONTAINER ID        IMAGE               COMMAND                  CREATED              STATUS              PORTS                NAMES
86a654873eaf        nginx:latest        "/docker-entrypoint.…"   About a minute ago   Up About a minute   0.0.0.0:80->80/tcp   scyun01


#IP地址
[root@node1 src]# docker inspect 86a654873eaf |grep -ai ipaddr|tail -1|grep -aiowE "([0-9]{1,3}\.){3}[0-9]{1,3}"
172.17.0.2

查看容器id 或名称

[root@node1 src]# docker ps |awk 'NR>1 {print $1}'
86a654873eaf
[root@node1 src]# docker ps |awk 'NR>1 {print $NF}'
scyun01

进入容器内部

[root@node1 src]# docker exec -it $(docker ps |awk 'NR>1 {print $NF}') /bin/bash
root@86a654873eaf:/#

修改默认配置文件

root@86a654873eaf:/etc/nginx/conf.d# sed -i -e '/#/d' -e '/^$/d' -e '/::/d' default.conf

root@86a654873eaf:/etc/nginx/conf.d# sed -i -e 's/localhost/www.wscyun.com/g' -e 's#/usr/share/nginx/html#/data/webapps/#g' default.conf 
root@86a654873eaf:/etc/nginx/conf.d# cat default.conf 
server {
    listen       80;
    server_name  www.wscyun.com;
    location / {
        root   /data/webapps/;
        index  index.html index.htm;
    }
    error_page   500 502 503 504  /50x.html;
    location = /50x.html {
        root   /data/webapps/;
    }
}

root@86a654873eaf:/etc/nginx/conf.d# mkdir -p /data/webapps
root@86a654873eaf:/etc/nginx/conf.d# cat >/data/webapps/index.html<<EOF
> this is www.wscyun.com page
> EOF
root@86a654873eaf:/etc/nginx/conf.d# nginx -t
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful
root@86a654873eaf:/etc/nginx/conf.d# nginx -s reload
2021/03/18 09:23:32 [notice] 60#60: signal process started

 

 

继续阅读
Docker最后更新:2021-7-4
scadm
  • 本文由 发表于 2021年5月9日12:09:50
  • 转载请务必保留本文链接:https://www.wscyun.com/1426
Hadoop 节点扩容 运维

Hadoop 节点扩容

配置好hosts解析 # cat /etc/hosts 127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdom...
hadoop 分布式存储部署 运维

hadoop 分布式存储部署

Hadoop概念 Hadoop实现了一个分布式文件系统( Distributed File System),其中一个组件是HDFS。HDFS有高容错性的特点,并且设计用来部署在低廉的(low-cost...
CEPH分布式存储 运维

CEPH分布式存储

ceph简介: Ceph是一种为优秀的性能、可靠性和可扩展性而设计的统一的、分布式文件系统。ceph 的统一体现在可以提供文件系统、块存储和对象存储,分布式体现在可以动态扩展。在国内一些公司的云环境中...
linux问题汇总(持续更新) 运维

linux问题汇总(持续更新)

本篇文章主要收集一些运维经常遇到的报错,记录下来方便以后查看,以及一些报错的解决方法。 1,启动docker容器报write /proc/self/attr/keycreate: permission...