前言:创建自己的docker image并上传到hub.docker仓库
⚠️先注册hub账户 https://hub.docker.com/
1.创建Dockerfile
2.构建Image
3.打标签Image
4.登录hub.docker
4.上传Image
1.创建Dockerfile
这里以swoole环境为例子,创建一个自己的docker开发环境
# 基础镜像
FROM php:7.1
# 作者信息
MAINTAINER degree757 <degree757@qq.com>
# 环境变量
ENV SWOOLE_VERSION 1.10.3
# Timezone
RUN /bin/cp /usr/share/zoneinfo/Asia/Shanghai /etc/localtime \
&& echo 'Asia/Shanghai' > /etc/timezone
# 依赖
RUN apt-get update \
&& apt-get install -y \
curl \
wget \
git \
zip \
libz-dev \
libssl-dev \
libnghttp2-dev \
libpcre3-dev \
&& apt-get clean \
&& apt-get autoremove
# PDO extension
RUN docker-php-ext-install pdo_mysql
# Bcmath extension
RUN docker-php-ext-install bcmath
# Swoole extension
RUN wget https://github.com/swoole/swoole-src/archive/v${SWOOLE_VERSION}.tar.gz -O swoole.tar.gz \
&& mkdir -p swoole \
&& tar -xf swoole.tar.gz -C swoole --strip-components=1 \
&& rm swoole.tar.gz \
&& ( \
cd swoole \
&& phpize \
&& ./configure --enable-mysqlnd --enable-openssl --enable-http2 \
&& make -j$(nproc) \
&& make install \
) \
&& rm -r swoole \
&& docker-php-ext-enable swoole
2.构建Image
在Dockerfile目录下,运行构建Image命令
➜ docker build -t swoole .
3.打标签Image
docker image ls查看当前本地镜像
➜ docker image ls
REPOSITORY TAG IMAGE ID CREATED SIZE
swoole 1.10 dbee969e838c 2 hours ago 425MB
php 7.1 8bbf0726af2d 3 weeks ago 358MB
➜ docker tag dbee969e838c degree757/swoole:1.10
给swoole镜像打个标签 docker tag dbee969e838c degree757/swoole:1.10
- degree757 是你们自己在hub.docker的ID
- swoole:1.10 镜像以及版本
⚠️dbee969e838c是你们自己的IMAGE ID
4.登录hub.docker
通过login命令登录
➜ docker login
Login with your Docker ID to push and pull images from Docker Hub. If you don't have a Docker ID, head over to https://hub.docker.com to create one.
Username: degree757
Password:
Login Succeeded
4.上传Image
推送本地镜像到hub.docker,至此完毕
➜ docker push degree757/swoole
总结
发布镜像成功,开启持续集成
网友评论