创建一个容器,启动后使用curl命令请求指定的地址
方法一、固定的地址,创建Dockerfile前先修改entrypoint.sh里的地址
准备entrypoint.sh
curl -s http://www.baidu.com
创建Dockerfile文件
FROM docker.io/alpine:latest RUN echo "https://mirrors.aliyun.com/alpine/v3.6/main/" > /etc/apk/repositories RUN echo "https://mirrors.aliyun.com/alpine/v3.6/community/" >> /etc/apk/repositories RUN ["apk","update"] RUN ["apk","add","curl"] COPY entrypoint.sh / RUN chmod 777 /entrypoint.sh CMD ["sh", "-c","/entrypoint.sh"]
方法二、带参数,默认请求www.baidu.com,启动容器通过传参改成www.qq.com
FROM docker.io/alpine:latest RUN echo "https://mirrors.aliyun.com/alpine/v3.6/main/" > /etc/apk/repositories RUN echo "https://mirrors.aliyun.com/alpine/v3.6/community/" >> /etc/apk/repositories RUN ["apk","update"] RUN ["apk","add","curl"] ENV URL=http://www.baidu.com CMD ["sh", "-c","curl -s ${URL}"]
启动容器时传参 docker run -d -e URL="http://www.qq.com" curl:latest
镜像启动后执行完就退出了
可以通过docker logs ContainerID 查看返回的请求结果判断是否请求成功
标签:容器,RUN,com,apk,sh,curl,制作,alpine From: https://www.cnblogs.com/hm1825/p/16857248.html