docker 操作手册(四)Dockerfile 与 image push

Dockerfile

入门:https://docs.docker.com/build/building/packaging/

开始编写

新建目录,创建文件Dockerfile:

FROM nginx
RUN echo '<h1>Hello, Docker!</h1>' > /usr/share/nginx/html/index.html

构建镜像并发布:

docker build --tag=imgxx/test .
docker push imgxx/test

docker image push

该命令将镜像推送至仓库,也缩写为:docker push
入门:https://docs.docker.com/engine/reference/commandline/image_push/
示例:

docker container commit c16378f943fe rhel-httpd:latest
docker image tag rhel-httpd:latest registry-host:5000/imgxx/test:latest
docker image push registry-host:5000/imgxx/test:latest

完整示例

FROM node:18.14
EXPOSE 80
RUN \
    apt update && \
    apt install -y git ffmpeg python && \
    wget https://github.com/yt-dlp/yt-dlp/releases/latest/download/yt-dlp -O /usr/bin/yt-dlp && \
    chmod +x /usr/bin/yt-dlp && \
    git clone https://github.com/develon2015/Youtube-dl-REST /Youtube-dl-REST && \
    cd /Youtube-dl-REST && \
    npm i
WORKDIR /Youtube-dl-REST
CMD npm run start

构建并运行:

docker build --tag=imgxx/youtube-dl-rest .
docker volume create vol
docker run -it -d --name youtube-dl-rest -p 80:80 -v vol:/Youtube-dl-REST imgxx/youtube-dl-rest
vi /var/lib/docker/volumes/vol/_data/cookies.txt  # 目录被挂载到主机volume中

参考

https://yeasy.gitbook.io/docker_practice/image/build
https://docs.docker.com/engine/reference/builder/

posted @ 2024-01-29 16:31  develon  阅读(77)  评论(0编辑  收藏  举报