Dockerfile Syntax Cheatsheet




FROM

Syntax

FROM <image>:<tag>

Example

FROM ubuntu:16.04

ENV

Syntax

ENV <key> <value>

Example

ENV JAVA_HOME       /usr/lib/jvm/java-8-oracle

RUN

Syntax

RUN <command>

Example

RUN apt-get update

EXPOSE

Syntax

EXPOSE <port> [<port> ...]

Example

EXPOSE 8080 9200

COPY

Syntax

COPY <src> [<src> ...] <dest>

Example

COPY file1.txt /opt/app/file1.txt

ADD

Syntax

ADD <src> [<src> ...] <dest>

Example

ADD file1.txt /opt/app/file1.txt
ADD jdk-8u120-linux-x64.tar.gz /usr/local/  # ADD unzips for you
ADD http://example.com/app.tar.xz /opt/app/ # ADD also support urls

VOLUME

Syntax

VOLUME </path/from/host> </path/from/docker-container>

Example

VOLUME /data /mongodb/db/data

WORKDIR

Sets working directory where other commands run Syntax

WORKDIR <path>

Example

WORKDIR /opt/app

CMD

Syntax

CMD <command> [<command> ...]

Example

CMD ['node' 'index.js']


┬ęCopyright 2020 OneCompiler | Privacy Policy | Terms & Conditions