【Docker】动手写Dockerfile学习Docker

# Use an official image as a parent image
FROM centos:7.2.1511

# install related packages
ENV ENVIRONMENT DOCKER_PROD

# Set the working directory to /app
WORKDIR /app

# Copy the current directory contents into the container at /app
ADD ./main.py /app
ADD ./requirements.txt /app

RUN cd / && ln -sf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime \
    && yum makecache \
    && yum install -y wget aclocal automake autoconf make gcc gcc-c++ python3-devel mysql-devel bzip2 libffi-devel epel-release \
    && yum clean all \
# install related packages
    && yum install -y python-pip \
    && yum install -y python-setuptools \
    && mkdir -m 755 -p /etc/supervisor/conf.d \
    && yum install -y supervisor \
    && yum install -y bzip2-devel \
    && yum install -y xz-devel \
    && yum clean all \
# install python
    && wget https://npm.taobao.org/mirrors/python/3.7.0/Python-3.7.0.tar.xz \
    && tar -xvf Python-3.7.0.tar.xz -C /usr/local/ \
    && rm -rf Python-3.7.0.tar.xz \
    && cd /usr/local/Python-3.7.0 \
    && ./configure && make && make install \
# Install any needed packages specified in requirements.txt
    && pip3 install --upgrade pip \
    && cd /app && pip3 install -r requirements.txt

# Define environment variable
ENV NAME World

# Run when the container launches
CMD ["python3", "main.py"]
1、按照当前目录的Dockerfile打包镜像
docker build -t guoqiang .  
2、查看当前系统docker镜像
docker image ls
3、清理指定的docker镜像
docker rmi -f XXX
4、启动指定的docker镜像
docker run guoqiang:latest 
5、注意事项
mac下docker不支持--net=host模式

你可能感兴趣的:(【Docker】动手写Dockerfile学习Docker)