Copy the file from local system to docker container
[root@ip-172-31-82-31 dockerfiles]# vi Dockerfile
[root@ip-172-31-82-31 dockerfiles]# cat Dockerfile
FROM ubuntu:16.04
LABEL name="Raj Gupta"
LABEL email="rajkumargupta14@gmail.com"
ENV NAME raj
ENV PASS password
RUN pwd>/tmp/1st.txt
RUN cd /tmp/
RUN pwd>tmp/2nd.txt
WORKDIR /tmp
RUN pwd>/tmp/3rd.txt
RUN mkdir -p /tmp/project
COPY testproject /tmp/project/
[root@ip-172-31-82-31 dockerfiles]# vi Dockerfile
[root@ip-172-31-82-31 dockerfiles]# cat Dockerfile
FROM ubuntu:16.04
LABEL name="Raj Gupta"
LABEL email="rajkumargupta14@gmail.com"
ENV NAME raj
ENV PASS password
RUN pwd>/tmp/1st.txt
RUN cd /tmp/
RUN pwd>tmp/2nd.txt
WORKDIR /tmp
RUN pwd>/tmp/3rd.txt
RUN mkdir -p /tmp/project
COPY testproject /tmp/project/
[root@ip-172-31-82-31 dockerfiles]# mkdir testproject
[root@ip-172-31-82-31 dockerfiles]# cd testproject/
[root@ip-172-31-82-31 testproject]# touch 1.txt
[root@ip-172-31-82-31 testproject]# touch 2.txt
[root@ip-172-31-82-31 testproject]# cd ..
[root@ip-172-31-82-31 dockerfiles]# docker image build -t rajubuntu:14 .
[root@ip-172-31-82-31 dockerfiles]# docker container run -P -it rajubuntu:14
root@5e68fe116639:/tmp# ls
1st.txt 2nd.txt 3rd.txt project
root@5e68fe116639:/tmp# cd project/
root@5e68fe116639:/tmp/project# ls
1.txt 2.txt
We can do same thing by ADD command also but one more benefit of add command is if you copy any .tar file from local to container by using ADD command then it will extract the tar file but copy command simply copy the tar file.
root@5e68fe116639:/tmp/project# [root@ip-172-31-82-31 dockerfiles]#
[root@ip-172-31-82-31 dockerfiles]# clear
[root@ip-172-31-82-31 dockerfiles]# vi Dockerfile
[root@ip-172-31-82-31 dockerfiles]# cat Dockerfile
FROM ubuntu:16.04
LABEL name="Raj Gupta"
LABEL email="rajkumargupta14@gmail.com"
ENV NAME raj
ENV PASS password
RUN pwd>/tmp/1st.txt
RUN cd /tmp/
RUN pwd>tmp/2nd.txt
WORKDIR /tmp
RUN pwd>/tmp/3rd.txt
RUN mkdir -p /tmp/project2
ADD testproject /tmp/project2/
[root@ip-172-31-82-31 dockerfiles]# docker image build -t rajubuntu:81 .
[root@ip-172-31-82-31 dockerfiles]# docker container run -P -it rajubuntu:81
root@457e0e04200f:/tmp# ls
1st.txt 2nd.txt 3rd.txt project2
root@457e0e04200f:/tmp# cd project2/
root@457e0e04200f:/tmp/project2# ls
1.txt 2.txt
root@457e0e04200f:/tmp/project2#
No comments:
Post a Comment