安恒赛题出题模板记录

最近给安恒投稿题目,这篇文章用于记录 Dockerfile 内容。所有镜像基于 Ubuntu 官方镜像

python3 + Django 2.2.11

FROM ubuntu:16.04

RUN sed -i 's/archive.ubuntu.com/mirrors.aliyun.com/g' /etc/apt/sources.list && 
	sed -i 's/security.ubuntu.com/mirrors.aliyun.com/g' /etc/apt/sources.list && 
	apt update -y && apt upgrade -y && apt install -y python3 && apt install -y python3-pip && mkdir /usr/src/app/ &&
	mkdir ~/.pip/ && touch ~/.pip/pip.conf &&
	echo '[global]' > ~/.pip/pip.conf && sed -i '1aindex-url = https://mirrors.aliyun.com/pypi/simple/

[install]
trusted-host=mirrors.aliyun.com' ~/.pip/pip.conf

WORKDIR /usr/src/app
COPY requirements.txt ./
COPY ./challenge ./
RUN pip3 install -r requirements.txt && python3 manage.py makemigrations && python3 manage.py migrate
EXPOSE 80
CMD ["python3", "manage.py", "runserver", "0.0.0.0:80"]

PHP7 + apache2

FROM ubuntu:16.04

RUN sed -i 's/archive.ubuntu.com/mirrors.aliyun.com/g' /etc/apt/sources.list && 
        sed -i 's/security.ubuntu.com/mirrors.aliyun.com/g' /etc/apt/sources.list && 
        apt update -y && apt upgrade -y && apt install -y apache2 && 
        sed -i "1i ServerName localhost:80" /etc/apache2/apache2.conf && 
        apt install -y php && apt install -y libapache2-mod-php && 
        rm -rf /var/www/html/index.html

RUN echo "flag{*******}" > /flag

ADD www /var/www/html/

RUN chmod 777 /var/www/html/session/ && 
	service apache2 restart

EXPOSE 80
	
CMD ["/usr/sbin/apache2ctl","-D","FOREGROUND"]

docker 命令

根据镜像生成容器

docker run -itd --name ubuntu-test ubuntu:16.04

进入容器

docker exec -it 09cc51fd0baf /bin/bash

停止容器

docker stop f6848d0e59ac

删除容器

docker container rm f6848d0e59ac

删除镜像

docker rmi f6848d0e59ac

根据 Dockerfile 构建镜像

docker build -t test:v1 .

根据构建的镜像运行容器

docker run --name test2 -it -d -p 20003:80 test:v1

导出镜像

docker save -o hackus.tar test:v10

原文地址:https://www.cnblogs.com/peri0d/p/12851135.html