Lab 3: Create an image with COPY instruction

Create an image with COPY instruction

Dockerfile

FROM nginx:alpine
LABEL maintainer="microfocus"

COPY index.html /usr/share/nginx/html/
ENTRYPOINT ["nginx", "-g", "daemon off;"]

Lets create the index.html file

echo "Welcome to Docker" > index.html

Building Docker Image

docker image build -t cpy:v1 .

Staring the container

docker container run -d --rm --name myapp1 -p 80:80 cpy:v1

Checking index file

curl localhost

Welcome to Docker

COPY instruction in Multi-stage Builds

Dockerfile

FROM alpine AS stage1
LABEL maintainer="microfocus"
RUN echo "Welcome to Docker" > /opt/index.html

FROM nginx:alpine
LABEL maintainer="nishanth"
COPY --from=stage1 /opt/index.html /usr/share/nginx/html/
ENTRYPOINT ["nginx", "-g", "daemon off;"]

Building Docker Image

$ docker image build -t cpy:v2 .

Staring the container

$ docker container run -d --rm --name myapp2 -p 8080:80 cpy:v2

Checking index file

curl localhost:8080

Last updated

Was this helpful?