安装docker

brew install bash-completion
brew cask install docker

初始化docker

安装完成之后,应用会增加一个Docker app,启动后需要输入密码来初始化,然后就可以使用命令行docker命令了。

构建docker镜像

准备Dockerfile

比如:

FROM centos:7

LABEL maintainer="suninf <sunjiangwei@yeah.net>"

# RUN yum update && yum clean all

RUN yum update -y

RUN yum install -y sudo vim

RUN yum install -y git wget rsync

# for coturn building
RUN yum install -y gcc make redhat-rpm-config doxygen rpm-build

RUN yum install -y sqlite

RUN yum install -y mysql-devel sqlite-devel openssl-devel postgresql-devel

RUN useradd -d/home/builder -Gwheel -mN builder

RUN echo builder | passwd --stdin builder

构建镜像

假设Dockerfile在builder_centos7_dir目录下,要构建名为docker_centos7的镜像

docker build -t docker_centos7 builder_centos7_dir

启动docker镜像

alias docker_run_centos7='docker run -it -v ~/workspace:/workspace -w /home/builder -p 50000:50000/udp -p 8000:8000/udp -p 60000:60000/udp -p 8080:8080 -p 8001:8001 docker_centos7'

以后启动镜像,只需要执行:docker_run_centos7