cmdref.net - Cheat Sheet and Example

cmdref.net is command references/cheat sheets/examples for system engineers.

User Tools

Site Tools


Sidebar








Etc


Reference














.

middleware:container:docker:dockerfile



How to use Dockerfile

Reference

How to write Dockerfile

FROM Source image FROM name/web:ver1.0
MAINTAINER
ENV Environment variable ENV KEY=VALUE
RUN Execute the specified command RUN yum -y install httpd
ADD Add file to image ADD index.html /var/www/html/index.htm
EXPOSE Specify port number EXPOSE 80
CMD Command executed when container starts CMD [“service”,“httpd”,“start”]
ENTRYPOINT ENTRYPOINT [“/usr/sbin/httpd”, “-DFOREGROUND”]
WORKDIR Specify current directory WORKDIR /var/www/html
VOLUME Volume specification VOLUME /var/log/httpd


Example1

# mkdir test
# cd test
# vi Dockerfile
FROM centos

RUN yum update -y \
    && yum install httpd -y \
    && echo "hello world from dockerfile" > /var/www/html/index2.html \
    && yum clean all

ADD ./httpd/www/index.html /var/www/html/

EXPOSE 80

ENTRYPOINT ["/usr/sbin/httpd", "-DFOREGROUND"]
# docker build . -t mycentos_with_httpd_from_dockerfile
# docker images
# docker run -d --rm -p 8080:80 mycentos_with_httpd_from_dockerfile

http://x.x.x.x/index.html
http://x.x.x.x/index2.html




middleware/container/docker/dockerfile.txt · Last modified: 2020/05/15 by admin

Page Tools