龙空技术网

centos7安装docker

乡村教育信息化 134

前言:

当前我们对“centos7dockerredis”大概比较关注,看官们都想要学习一些“centos7dockerredis”的相关文章。那么小编在网络上搜集了一些对于“centos7dockerredis””的相关资讯,希望姐妹们能喜欢,小伙伴们一起来了解一下吧!


1.把yum包更新到最新(生产环境谨慎)

yum update

2.安装需要的软件包, yum-util 提供yum-config-manager功能,另外两个是devicemapper驱动依赖的

yum install -y yum-utils device-mapper-persistent-data lvm2

3. 设置yum源

yum-config-manager --add-repo

Loaded plugins: fastestmirror

adding repo from:

grabbing file to /etc/yum.repos.d/docker-ce.repo

repo saved to /etc/yum.repos.d/docker-ce.repo


4,可以查看所有仓库中所有docker版本,并选择特定版本安装

yum list docker-ce --showduplicates | sort -r

5.安装Docker,命令:yum install docker-ce-版本号,我选的是18.03.1.ce-1.el7.centos,如下

yum install docker-ce-18.03.1.ce-1.el7.centos


6. 启动Docker,命令:

systemctl start docker

然后加入开机启动,如下:

systemctl start docker

systemctl enable docker


7,验证安装是否成功(有client和service两部分表示docker安装启动都成功了)

docker version

Client:

Version: 18.03.1-ce

API version: 1.37

Go version: go1.9.5

Git commit: 9ee9f40

Built: Thu Apr 26 07:20:16 2018

OS/Arch: linux/amd64

Experimental: false

Orchestrator: swarm


Server:

Engine:

Version: 18.03.1-ce

API version: 1.37 (minimum version 1.12)

Go version: go1.9.5

Git commit: 9ee9f40

Built: Thu Apr 26 07:23:58 2018

OS/Arch: linux/amd64

Experimental: false


8.docker常用命令

(1)启动docker

systemctl start docker.service

(2)停止docker

systemctl stop docker


(3)查看当前docker状态

systemctl status docker

(4) 拉取镜像

从 docker hub 拉取

下面的例子将从Docker Hub 仓库下载一个 Tomcat 7 版本的服务器镜像。

docker pull tomcat:7

这是docker默认的公用仓库,不过缺点是国内下载会比较慢。

(5)镜像加速 :从 ustc 拉取(建议使用)

在宿主机器编辑文件:

vi /etc/docker/daemon.json

请在该配置文件中加入(没有该文件的话,请先建一个):

{

"registry-mirrors":[";]

}

"registry-mirrors":[";] 阿里云


最后,需要重启 docker 服务

systemctl restart docker

docker search tomcat

(6)删除镜像

docker rmi hello-world

docker rmi -f hello-world 强制

docker rmi -f$(docker image -q)

(7)启动交互式容器

docker run -it --name centos (centos 为镜像名称)

docker run -it --name 0f3e07c01...(镜像ID) -

(8)启动后台守护容器

docker run -d --name 0f3e07c01...(镜像ID)

docker run -d centos /bin/sh -c "while true;do echo hello world;sleep 2;done"

docker logs -t -f 容器id


(9)退出容器 exit

(10)其他

docker inspect 容器id

docker exec -it 容器id /bin/bash

docker exec -it 容器id ls -l /tmp

docker ps 查看运行中的容器

docker start/stop/kill 容器名称 或id

docker cp 容器id:/tmp/yum.log /root

docker run -it -p 8888:8080 centos

进入交互 docker exec -it 容器id /bin/bash

(11)容器数据卷

命令添加 dockerfile

1.docker run -it -v /myData:/myDockerdata centos

2.dockerfile

from centos

VOLUME ["/myData1","/myData2"]

CMD echo “finished,------success1”

CMD /bin/bash

dockerfile 创建容器


docker build -f /mydocker/Dockerfile -t tanchao/centos .

docker run -it --name dc01 zzyy/centos


volumes-from容器间传递共享

docker run -it --name dc02 --volumes-from dc01 tanchao/centos


dockerfile 样例

保留字

RUN RUN groupadd -r -g 999 redis && useradd -r -g redis -u 999 redis

EXPOSE 端口

CMD / ENTRYPOINT


centos

FROM scratch

ADD centos-7-x86_64-docker.tar.xz /

LABEL org.label-schema.schema-version="1.0" \

org.label-schema.name="CentOS Base Image" \

org.label-schema.vendor="CentOS" \

org.label-schema.license="GPLv2" \

org.label-schema.build-date="20191001"

CMD ["/bin/bash"]


FROM scratch

ADD centos-7-docker.tar.xz /

LABEL org.label-schema.schema-version = "1.0" \

org.label-schema.name="CentOS Base Image" \

org.label-schema.vendor="CentOS" \

org.label-schema.license="GPLv2" \

org.label-schema.build-date="20180531"

CMD ["/bin/bash"]


redis

FROM debian:buster-slim


# add our user and group first to make sure their IDs get assigned consistently, regardless of whatever dependencies get added

RUN groupadd -r -g 999 redis && useradd -r -g redis -u 999 redis

# grab gosu for easy step-down from root

#

ENV GOSU_VERSION 1.11

RUN set -eux; \

# save list of currently installed packages for later so we can clean up

savedAptMark="$(apt-mark showmanual)"; \

apt-get update; \

apt-get install -y --no-install-recommends \

ca-certificates \

dirmngr \

gnupg \

wget \

; \

rm -rf /var/lib/apt/lists/*; \

\

dpkgArch="$(dpkg --print-architecture | awk -F- '{ print $NF }')"; \

wget -O /usr/local/bin/gosu ";; \

wget -O /usr/local/bin/gosu.asc ";; \

\

# verify the signature

export GNUPGHOME="$(mktemp -d)"; \

gpg --batch --keyserver hkps://keys.openpgp.org --recv-keys B42F6819007F00F88E364FD4036A9C25BF357DD4; \

gpg --batch --verify /usr/local/bin/gosu.asc /usr/local/bin/gosu; \

gpgconf --kill all; \

rm -rf "$GNUPGHOME" /usr/local/bin/gosu.asc; \

\

# clean up fetch dependencies

apt-mark auto '.*' > /dev/null; \

[ -z "$savedAptMark" ] || apt-mark manual $savedAptMark > /dev/null; \

apt-get purge -y --auto-remove -o APT::AutoRemove::RecommendsImportant=false; \

\

chmod +x /usr/local/bin/gosu; \

# verify that the binary works

gosu --version; \

gosu nobody true

ENV REDIS_VERSION 4.0.14

ENV REDIS_DOWNLOAD_URL

ENV REDIS_DOWNLOAD_SHA 1e1e18420a86cfb285933123b04a82e1ebda20bfb0a289472745a087587e93a7

RUN set -eux; \

\

savedAptMark="$(apt-mark showmanual)"; \

apt-get update; \

apt-get install -y --no-install-recommends \

ca-certificates \

wget \

\

gcc \

libc6-dev \

make \

; \

rm -rf /var/lib/apt/lists/*; \

\

wget -O redis.tar.gz "$REDIS_DOWNLOAD_URL"; \

echo "$REDIS_DOWNLOAD_SHA *redis.tar.gz" | sha256sum -c -; \

mkdir -p /usr/src/redis; \

tar -xzf redis.tar.gz -C /usr/src/redis --strip-components=1; \

rm redis.tar.gz; \

\

# disable Redis protected mode [1] as it is unnecessary in context of Docker

# (ports are not automatically exposed when running inside Docker, but rather explicitly by specifying -p / -P)

# [1]:

grep -q '^#define CONFIG_DEFAULT_PROTECTED_MODE 1$' /usr/src/redis/src/server.h; \

sed -ri 's!^(#define CONFIG_DEFAULT_PROTECTED_MODE) 1$!\1 0!' /usr/src/redis/src/server.h; \

grep -q '^#define CONFIG_DEFAULT_PROTECTED_MODE 0$' /usr/src/redis/src/server.h; \

# for future reference, we modify this directly in the source instead of just supplying a default configuration flag because apparently "if you specify any argument to redis-server, [it assumes] you are going to specify everything"

# see also

# (more exactly, this makes sure the default behavior of "save on SIGTERM" stays functional by default)

\

make -C /usr/src/redis -j "$(nproc)"; \

make -C /usr/src/redis install; \

\

# TODO (deduplicate "redis-server" copies)

serverMd5="$(md5sum /usr/local/bin/redis-server | cut -d' ' -f1)"; export serverMd5; \

find /usr/local/bin/redis* -maxdepth 0 \

-type f -not -name redis-server \

-exec sh -eux -c ' \

md5="$(md5sum "$1" | cut -d" " -f1)"; \

test "$md5" = "$serverMd5"; \

' -- '{}' ';' \

-exec ln -svfT 'redis-server' '{}' ';' \

; \

\

rm -r /usr/src/redis; \

\

apt-mark auto '.*' > /dev/null; \

[ -z "$savedAptMark" ] || apt-mark manual $savedAptMark > /dev/null; \

apt-get purge -y --auto-remove -o APT::AutoRemove::RecommendsImportant=false; \

\

redis-cli --version; \

redis-server --version

RUN mkdir /data && chown redis:redis /data

VOLUME /data

WORKDIR /data

COPY docker-entrypoint.sh /usr/local/bin/

ENTRYPOINT ["docker-entrypoint.sh"]

EXPOSE 6379

CMD ["redis-server"]

编写

FROM centos

ENV MYPATH /usr/local

WORKDIR $MYPAHT

RUN yum -y install vim

RUN yum -y install net-tools

EXPOSE 80

CMD echo $MYPATH

CMD echo "success ---------ok"

CMD /bin/bash



提交镜像

1.docker commit -a ='zhuozhe' -m="shuoming" 容器id at xxx/tomcat:1.2

2.push

阿里云

公网地址 registry.cn-hangzhou.aliyuncs.com/tanchao/mydocker

专有网络registry-vpc.cn-hangzhou.aliyuncs.com/tanchao/mydocker

经典网络registry-internal.cn-hangzhou.aliyuncs.com/tanchao/mydocker

标签: #centos7dockerredis