【Docker】動手寫Dockerfile學習Docker

國強_dev發表於2020-10-09
# 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模式

相關文章