<p><code>The docker build command builds Docker images from a Dockerfile and a “context”. A build’s context is the set of files located in the specified PATH or URL. The build process can refer to any of the files in the context. For example, your build can use a COPY instruction to reference a file in the context.</code></p>
<p>From <a href="https://docs.docker.com/engine/reference/commandline/build/" rel="nofollow noreferrer">docker build</a> documentation.</p>
<p>As you run the docker build with the <code>.</code> path for the context, it will try to find the folder <code>home/nicholas/html</code> from the context <code>root@mordor:/home/nicholas/docker/nginx</code></p>
<p>The <a href="https://docs.docker.com/engine/reference/builder/#copy" rel="nofollow noreferrer">COPY command</a> documentation shows some examples</p>

CC BY-SA 4.0
2020-11-14T07:34:40.177Z
yet the copy command wasn't, and isn't, acting as expected.
Nicholas Saunders
CC BY-SA 4.0
2020-11-14T08:45:09.683Z
If you push minimal files into a repository, I can drive deep a little bit ;-)
Benjamin Longearet
CC BY-SA 4.0
2020-11-14T04:03:29.280Z
2020-11-14T04:03:29.280Z
Benjamin Longearet
<p>This at least builds and runs:</p>
<pre><code>root@mordor:/home/nicholas/docker/nginx# 
root@mordor:/home/nicholas/docker/nginx# ls -al
total 16
drwxrwxr-x 2 nicholas nicholas 4096 Nov 13 17:18 .
drwxrwxr-x 3 nicholas nicholas 4096 Nov 13 16:12 ..
-rw-rw-r-- 1 nicholas nicholas   49 Nov 13 17:18 dockerfile
-rw-rw-r-- 1 nicholas nicholas   56 Nov 13 17:18 index.html
root@mordor:/home/nicholas/docker/nginx# 
root@mordor:/home/nicholas/docker/nginx# cat dockerfile 
FROM nginx
COPY index.html /usr/share/nginx/html
root@mordor:/home/nicholas/docker/nginx# 
root@mordor:/home/nicholas/docker/nginx# cat index.html 



hello world

how do I put this file in a diff dir?


root@mordor:/home/nicholas/docker/nginx# 
root@mordor:/home/nicholas/docker/nginx# docker build -t some-content-nginx .
Sending build context to Docker daemon  3.072kB
Step 1/2 : FROM nginx
 ---&gt; c39a868aad02
Step 2/2 : COPY index.html /usr/share/nginx/html
 ---&gt; Using cache
 ---&gt; 07a94375fb55
Successfully built 07a94375fb55
Successfully tagged some-content-nginx:latest
root@mordor:/home/nicholas/docker/nginx# 
root@mordor:/home/nicholas/docker/nginx# docker run --name some-nginx -d -p 8080:80 some-content-nginx
2c912aa5ce5c8b864a6fe79a18ee8e833874f85a75fed1c7020163ca7b90bedb
root@mordor:/home/nicholas/docker/nginx# 
</code></pre>
<p>although I can't seem to get anything from navigating to <code>localhost</code> so I'll have to look closer at the <code>container</code> which is built.</p>

CC BY-SA 4.0
2020-11-14T01:24:56.197Z
2020-11-14T01:24:56.197Z
Nicholas Saunders
<p><a href="https://hub.docker.com/_/nginx" rel="nofollow noreferrer">How do I copy</a> an <code>index.html</code> file into <code>nginx</code>?</p>
<pre><code>root@mordor:/home/nicholas/docker/nginx# 
root@mordor:/home/nicholas/docker/nginx# ll
total 12
drwxrwxr-x 2 nicholas nicholas 4096 Nov 13 16:18 ./
drwxrwxr-x 3 nicholas nicholas 4096 Nov 13 16:12 ../
-rw-rw-r-- 1 nicholas nicholas   60 Nov 13 16:18 dockerfile
root@mordor:/home/nicholas/docker/nginx# 
root@mordor:/home/nicholas/docker/nginx# cat dockerfile 
FROM nginx
COPY /home/nicholas/html /usr/share/nginx/html


root@mordor:/home/nicholas/docker/nginx# 
root@mordor:/home/nicholas/docker/nginx# docker build -t some-content-nginx .
Sending build context to Docker daemon  2.048kB
Step 1/2 : FROM nginx
 ---&gt; c39a868aad02
Step 2/2 : COPY /home/nicholas/html /usr/share/nginx/html
COPY failed: stat /var/snap/docker/common/var-lib-docker/tmp/docker-builder726461098/home/nicholas/html: no such file or directory
root@mordor:/home/nicholas/docker/nginx# 
root@mordor:/home/nicholas/docker/nginx# ls /home/nicholas/html/
index.html
root@mordor:/home/nicholas/docker/nginx# 
root@mordor:/home/nicholas/docker/nginx# cat /home/nicholas/html/index.html 



index
hello world



nicholas@mordor:~/html$ 
</code></pre>
<p>I'm unclear on the source and destination, which might be complicated by <code>docker</code> having been installed from <code>snap</code>.</p>
<hr />
<p><a href="https://devops.stackexchange.com/q/10597/23443">Looks</a> like <code>ansible</code> has slightly clearer, at least for me, syntax:</p>
<pre><code>  tasks:
  - name: &quot;Copying files&quot;
    copy:
      src: files/{{ item }}
      dest: /my/folder/
    with_items:
      - file.txt
</code></pre>
<p>or perhaps I'm doing something incorrectly.</p>

<docker><docker-compose><dockerfile><nginx><ubuntu>
How to copy HTML files to include into nginx?
Nicholas Saunders
# How to copy HTML files to include into nginx?

(Asked by: username_0 on 2020-11-14)

How do I copy an index.html file into nginx?
root@mordor:/home/nicholas/docker/nginx# 
root@mordor:/home/nicholas/docker/nginx# ll
total 12
drwxrwxr-x 2 nicholas nicholas 4096 Nov 13 16:18 ./
drwxrwxr-x 3 nicholas nicholas 4096 Nov 13 16:12 ../
-rw-rw-r-- 1 nicholas nicholas   60 Nov 13 16:18 dockerfile
root@mordor:/home/nicholas/docker/nginx# 
root@mordor:/home/nicholas/docker/nginx# cat dockerfile 
FROM nginx
COPY /home/nicholas/html /usr/share/nginx/html


root@mordor:/home/nicholas/docker/nginx# 
root@mordor:/home/nicholas/docker/nginx# docker build -t some-content-nginx .
Sending build context to Docker daemon  2.048kB
Step 1/2 : FROM nginx
 ---> c39a868aad02
Step 2/2 : COPY /home/nicholas/html /usr/share/nginx/html
COPY failed: stat /var/snap/docker/common/var-lib-docker/tmp/docker-builder726461098/home/nicholas/html: no such file or directory
root@mordor:/home/nicholas/docker/nginx# 
root@mordor:/home/nicholas/docker/nginx# ls /home/nicholas/html/
index.html
root@mordor:/home/nicholas/docker/nginx# 
root@mordor:/home/nicholas/docker/nginx# cat /home/nicholas/html/index.html 



index
hello world



nicholas@mordor:~/html$ 

I'm unclear on the source and destination, which might be complicated by docker having been installed from snap.

Looks like ansible has slightly clearer, at least for me, syntax:
  tasks:
  - name: "Copying files"
    copy:
      src: files/{{ item }}
      dest: /my/folder/
    with_items:
      - file.txt

or perhaps I'm doing something incorrectly.

**Tags:** docker, docker-compose, dockerfile, nginx, ubuntu


---

## 2 answers

### Answer by username_1 on 2020-11-14. Score: 1 | Accepted answer

`The docker build command builds Docker images from a Dockerfile and a “context”. A build’s context is the set of files located in the specified PATH or URL. The build process can refer to any of the files in the context. For example, your build can use a COPY instruction to reference a file in the context.`

From [docker build](https://docs.docker.com/engine/reference/commandline/build/) documentation.

As you run the docker build with the `.` path for the context, it will try to find the folder `home/nicholas/html` from the context `root@mordor:/home/nicholas/docker/nginx`

The [COPY command](https://docs.docker.com/engine/reference/builder/#copy) documentation shows some examples

> **Comments:**
> **username_0**: yet the copy command wasn't, and isn't, acting as expected.  
> **username_1**: If you push minimal files into a repository, I can drive deep a little bit ;-)  

---

### Answer by username_0 on 2020-11-14. Score: 0

This at least builds and runs:
root@mordor:/home/nicholas/docker/nginx# 
root@mordor:/home/nicholas/docker/nginx# ls -al
total 16
drwxrwxr-x 2 nicholas nicholas 4096 Nov 13 17:18 .
drwxrwxr-x 3 nicholas nicholas 4096 Nov 13 16:12 ..
-rw-rw-r-- 1 nicholas nicholas   49 Nov 13 17:18 dockerfile
-rw-rw-r-- 1 nicholas nicholas   56 Nov 13 17:18 index.html
root@mordor:/home/nicholas/docker/nginx# 
root@mordor:/home/nicholas/docker/nginx# cat dockerfile 
FROM nginx
COPY index.html /usr/share/nginx/html
root@mordor:/home/nicholas/docker/nginx# 
root@mordor:/home/nicholas/docker/nginx# cat index.html 



hello world

how do I put this file in a diff dir?


root@mordor:/home/nicholas/docker/nginx# 
root@mordor:/home/nicholas/docker/nginx# docker build -t some-content-nginx .
Sending build context to Docker daemon  3.072kB
Step 1/2 : FROM nginx
 ---> c39a868aad02
Step 2/2 : COPY index.html /usr/share/nginx/html
 ---> Using cache
 ---> 07a94375fb55
Successfully built 07a94375fb55
Successfully tagged some-content-nginx:latest
root@mordor:/home/nicholas/docker/nginx# 
root@mordor:/home/nicholas/docker/nginx# docker run --name some-nginx -d -p 8080:80 some-content-nginx
2c912aa5ce5c8b864a6fe79a18ee8e833874f85a75fed1c7020163ca7b90bedb
root@mordor:/home/nicholas/docker/nginx# 

although I can't seem to get anything from navigating to localhost so I'll have to look closer at the container which is built.


---

