Command docker run create empty container - docker

Command docker run create empty container. I mean that docker image builds successfully but when I run container there is no my changes. I am working on ubuntu 16.04 with vagrant. My docker file:
FROM node:6.2.0-wheezy
MAINTAINER Lukasz Migut
RUN mkdir -p /app
ADD package.json /app/package.json
RUN cd /app/ && \
npm cache clear && \
npm install --no-bin-links --quiet
RUN mkdir -p /var/www/backend
WORKDIR /var/www/backend
COPY entrypoint.sh /entrypoint.sh
CMD ["/bin/bash", "/entrypoint.sh"]
EXPOSE 8080
This is output after docker build .
Sending build context to Docker daemon 6.144 kB
Step 1 : FROM node:6.2.0-wheezy
6.2.0-wheezy: Pulling from library/node
47994b92ab73: Already exists
a3ed95caeb02: Already exists
9b7b75987c3c: Already exists
d66c4af59bfb: Already exists
26df7d6a7371: Already exists
b656b9b4e7eb: Already exists
e3753c84bc68: Already exists
Digest: sha256:9a04df0cd52487e2fb6d6316890380780209f9211f4767934c5f80f2da83a6bf
Status: Downloaded newer image for node:6.2.0-wheezy
---> ecbd08787958
Step 2 : MAINTAINER Lukasz Migut
---> Running in 2a1d31015aea
---> 6d6ff7769ec5
Removing intermediate container 2a1d31015aea
Step 3 : ADD package.json /app/package.json
---> 5a28cc87577c
Removing intermediate container 3df429908e6c
Step 4 : RUN cd /app/ && npm cache clear && npm install --no- bin-links --quiet
---> Running in 1fc442eb449a
npm info it worked if it ends with ok
npm info using npm#3.8.9
npm info using node#v6.2.0
npm info ok
blog-backend#0.0.1 /app
`-- hapi#13.4.1
+-- accept#2.1.1
+-- ammo#2.0.1
+-- boom#3.2.0
+-- call#3.0.1
+-- catbox#7.1.1
+-- catbox-memory#2.0.2
+-- cryptiles#3.0.1
+-- heavy#4.0.1
+-- hoek#4.0.0
+-- iron#4.0.1
+-- items#2.1.0
+-- joi#8.1.0
| +-- isemail#2.1.2
| `-- moment#2.13.0
+-- kilt#2.0.1
+-- mimos#3.0.1
| `-- mime-db#1.23.0
+-- peekaboo#2.0.1
+-- shot#3.0.1
+-- statehood#4.0.1
+-- subtext#4.0.3
| +-- content#3.0.1
| +-- pez#2.1.1
| | +-- b64#3.0.1
| | `-- nigel#2.0.1
| | `-- vise#2.0.1
| `-- wreck#7.2.1
`-- topo#2.0.1
---> ad5bf17db156
Removing intermediate container 1fc442eb449a
Step 5 : WORKDIR /var/www/backend
---> Running in 3f75e64f3880
---> 477162d999c0
Removing intermediate container 3f75e64f3880
Step 6 : COPY entrypoint.sh /entrypoint.sh
---> b0918e5611e2
Removing intermediate container b1c46f9175dd
Step 7 : CMD /bin/bash /entrypoint.sh
---> Running in fd2c72465c11
---> 275911ac22ca
Removing intermediate container fd2c72465c11
Step 8 : EXPOSE 8080
---> Running in d54c25afb6a1
---> f4ba799427cc
Removing intermediate container d54c25afb6a1
Successfully built f4ba799427cc
Command docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
<none> <none> f4ba799427cc 28 minutes ago 514.2 MB
node 6.2.0-wheezy ecbd08787958 8 days ago 503.9 MB
Next i try to run container with docker run -it node:6.2.0-wheezy /bin/bash
and when i login on container i can't see for example created folders form Dockerfile and no node_modules.
What i do wrong, why i can't see changes?

You built an image... it is the one tagged "< none >" in your docker images command. However, when you tried to run a container, you used the old image that you based your new image on. Your changes are in that new image, not the old one.
To get it to work you have to tag your new image with a name and use that name...
docker build -t MYIMAGENAME .
docker run -it MYIMAGENAME /bin/bash

Related

Docker not able to find/run binary

I have what I believe is a pretty simple setup.
I build a binary file outside of docker and then try to add it using this Dockerfile
FROM alpine
COPY apps/dist/apps /bin/
RUN chmod +x /bin/apps
RUN ls -al /bin | grep apps
CMD /bin/apps
And I think this should work.
The binary on its own seems to work on my host machine and I don't understand why it wouldn't on the docker image.
Anyways, the output I get is this:
docker build -t apps -f app.Dockerfile . && docker run apps
Sending build context to Docker daemon 287.5MB
Step 1/5 : alpine
---> d05cf6536f67
Step 2/5 : COPY apps/dist/apps /bin/
---> Using cache
---> c54d6d57154e
Step 3/5 : RUN chmod +x /bin/apps
---> Using cache
---> aa7e6adb0981
Step 4/5 : RUN ls -al /bin | grep apps
---> Running in 868c5e235d68
-rwxr-xr-x 1 root root 68395166 Dec 20 13:35 apps
Removing intermediate container 868c5e235d68
---> f052c06269b0
Step 5/5 : CMD /bin/apps
---> Running in 056fd02733e1
Removing intermediate container 056fd02733e1
---> 331600154cbe
Successfully built 331600154cbe
Successfully tagged apps:latest
/bin/sh: /bin/apps: not found
does this make sense, and am I just missing something obvious?
Your binary likely has dynamic links to libraries that don't exist inside the image filesystem. You can check those dynamic links with the ldd apps/dist/apps command.

is it possible to allow failure in COPY at a Dockerfile?

I have a multistage Docker file like this:
From A as a
WORKDIR /app
COPY . .
From B as b
COPY --from=a /app/path/to/a/file /destination/file/path
Sometimes the source-file of last COPY does not exist and this causes a failure in docker build. Is it possbile to do the magic w/o worrying about the existence of /app/path/to/a/file?
I don't suppose there is a way to allow for a failure in a COPY instruction, but what you could do is copy not a specific file, but the content of the folder that does exist (even if it's empty).
For example, imagine you have a folder structure like this
.
├── Dockerfile
└── test_folder
└── test_file
1 directory, 2 files
and you build from this Dockerfile:
FROM alpine as alp1
WORKDIR /app
COPY . .
FROM alpine
RUN mkdir /dest_folder
COPY --from=alp1 /app/test_folder/test_file /dest_folder
if works because the file does exist and if we were to delete the file from that folder, the COPY would fail.
So instead of copying /app/test_folder/test_file we could copy /app/test_folder/, which will copy EVERYTHING from inside the test_folder to /dest_folder in the second container, EVEN if there is nothing:
file removed:
.
├── Dockerfile
└── test_folder
1 directory, 1 file
building from:
FROM alpine as alp1
WORKDIR /app
COPY . .
FROM alpine
RUN mkdir /dest_folder
COPY --from=alp1 /app/test_folder/ /dest_folder
> docker build -t test .
Sending build context to Docker daemon 2.56kB
Step 1/6 : FROM alpine as alp1
---> 0a97eee8041e
Step 2/6 : WORKDIR /app
---> Using cache
---> 0a6fc3a90e15
Step 3/6 : COPY . .
---> Using cache
---> 076efaa3a8b9
Step 4/6 : FROM alpine
---> 0a97eee8041e
Step 5/6 : RUN mkdir /dest_folder
---> Using cache
---> 8d647b9a1573
Step 6/6 : COPY --from=alp1 /app/test_folder/ /dest_folder
---> Using cache
---> 361b0919c585
Successfully built 361b0919c585
Successfully tagged test:latest
dest_folder exists:
docker run -it --rm test ls
bin etc media proc sbin tmp
dest_folder home mnt root srv usr
dev lib opt run sys var
but nothing is inside
docker run -it --rm test ls -lah /dest_folder
total 8K
drwxr-xr-x 1 root root 4.0K Nov 24 14:06 .
drwxr-xr-x 1 root root 4.0K Nov 24 14:13 ..

docker container couldn't locate file but file is present

I am trying to package gotty into a Docker container but found a weird behavior.
$ tree
.
├── Dockerfile
├── gotty
└── gotty_linux_amd64.tar.gz
Dockerfile:
FROM alpine:3.11.3
RUN mkdir -p /home/gotty
WORKDIR /home/gotty
COPY gotty /home/gotty
RUN chmod +x /home/gotty/gotty
CMD ["/bin/sh"]
The image was built without issue:
[strip...]
Removing intermediate container 0dee1ab645e0
---> b5c6957d36e1
Step 7/9 : COPY gotty /home/gotty
---> fb1a1adec04a
Step 8/9 : RUN chmod +x /home/gotty/gotty
---> Running in 90031140da40
Removing intermediate container 90031140da40
---> 609e1a5453f7
Step 9/9 : CMD ["/bin/sh"]
---> Running in 30ce65cd4339
Removing intermediate container 30ce65cd4339
---> 099bc22ee6c0
Successfully built 099bc22ee6c0
The chmod changed the file mode successfully. So /home/gotty/gotty is present.
$ docker run -itd 099bc22ee6c0
9b219a6ef670b9576274a7b82a1b2cd813303c6ea5280e17a23a917ce809c5fa
$ docker exec -it 9b219a6ef670 /bin/sh
/home/gotty # ls
gotty
/home/gotty # ./gotty
/bin/sh: ./gotty: not found
Go into the container, the gotty command is there. I ran it with relative path. Why the not found?
You are running into one of the more notorious problems with Alpine: Musl, instead of glibc. Check out the output of ldd gotty. Try adding libc6-compat:
apk add libc6-compat
and see if that fixes it.

Docker cannot find file or directory with copy command

So I am pretty new to docker and it's setup but I have been messing around with this dockerfile for about half an hour trying to get a working image together for an angular 6 application that I have.
Aside from the messy dockerfile the last bit doesn't seem to be working.
So I am working inside of the /workdir directory for all this stuff, building my angular app, etc. Afterwards I move out to the root directory and then want to copy the /workdir/dist directory to the root /dist folder and then delete the working directory. I get a file or directory not found at the copy line. However if I run ls I see a workdir exists and if I run ls ./workdir/dist I see that there are files in it.
My linux scripting and docker understanding is very limited but I cannot see why this seems to fail.
FROM node:8
ENV ExposedPort 80
WORKDIR /workdir
COPY . /workdir
RUN npm install
RUN npm run production-angular
COPY package.json dist
COPY index.js dist
WORKDIR /
RUN ls
RUN ls workdir
RUN ls workdir/dist
COPY workdir/dist dist
CMD node index.js
EXPOSE ${ExposedPort}
My last few lines from the docker build command:
Step 9/15 : WORKDIR /
Removing intermediate container 10f69d248a51
---> d6184c6f0ceb
Step 10/15 : RUN ls
---> Running in c30b23783655
bin
boot
dev
etc
home
lib
lib64
media
mnt
opt
proc
root
run
sbin
srv
sys
tmp
usr
var
workdir
Removing intermediate container c30b23783655
---> fb74727468f6
Step 11/15 : RUN ls workdir
---> Running in e6bae18e3560
README.md
angular.json
dist
dockerfile
e2e
index.js
node_modules
package-lock.json
package.json
src
tsconfig.json
tslint.json
Removing intermediate container e6bae18e3560
---> c3e1f9f77d00
Step 12/15 : RUN ls workdir/dist
---> Running in 07923b11226e
3rdpartylicenses.txt
favicon.ico
index.html
index.js
main.1c74cb5a2b3da54e1148.js
package.json
polyfills.479875dfe4ba221bc297.js
runtime.a66f828dca56eeb90e02.js
styles.34c57ab7888ec1573f9c.css
Removing intermediate container 07923b11226e
---> 66ef563ba292
Step 13/15 : COPY workdir/dist dist
COPY failed: stat /var/lib/docker/tmp/docker-builder326636018/workdir/dist: no such file or directory
Change COPY ./workdir to COPY workdir
https://github.com/docker/for-linux/issues/90#issuecomment-326045261
Paths in a Dockerfile are always relative to the the context directory. The context directory is the positional argument passed to docker build (often .).
If there is no ./tmp in the context directory then this is the expected behaviour.

docker-compose volume not appearing in container

I'm trying to build a stack with one docker-compose that should contain another containers inside. This is to run a development environment with all my projects inside.
So the problem is the volume with application source isn't appearing on built image.
MacOS Sierra
Docker version 17.03.0-ce, build 60ccb22
Boot2Docker-cli version: v1.8.0
my directory tree
/dockers <======= one directory with all docker files for each project
docker-compose.yml <======= The main image
/project1 <======= dockerfile for each project
Dockerfile
/project2
Dockerfile
/project3
Dockerfile
/project1 <======= project1 source folder
test.txt
/project2
/project3
my docker-compose.yml
project1:
build: ./project1
volumes:
- ../project1/:/src
my dockerfile for project1
FROM python:2.7
RUN mkdir -p /src
WORKDIR /src
RUN echo "---------------------"
RUN ls -la
RUN echo "---------------------"
So I try to build the docker-compose file
$ sudo docker-compose build --no-cache
And then it shows an empty folder when I expect test.txt file
Building express
ERROR: Cannot locate specified Dockerfile: Dockerfile
➜ docker git:(master) ✗ sudo docker-compose build --no-cache
Building project1
Step 1/7 : FROM python:2.7
---> ca388cdb5ac1
Step 2/7 : RUN mkdir -p /src
---> Running in 393a462f7a44
---> 4fbeb32d88b3
Removing intermediate container 393a462f7a44
Step 3/7 : WORKDIR /src
---> 03ce193577ab
Removing intermediate container b1cd746b699a
Step 4/7 : RUN echo "--------------------------"
---> Running in 82df8a512c90
----------------------------
---> 6dea58ba5051
Removing intermediate container 82df8a512c90
Step 5/7 : RUN ls -la
---> Running in 905417d0cd19
total 8
drwxr-xr-x 2 root root 4096 Mar 23 17:12 . <====== EMPTY :(
drwxr-xr-x 1 root root 4096 Mar 23 17:12 .. <====== EMPTY :(
---> 53764caffb1a
Removing intermediate container 905417d0cd19
Step 6/7 : RUN echo "-----------------------------"
---> Running in 110e765d102a
----------------------------
---> b752230fd6dc
Removing intermediate container 110e765d102a
Step 7/7 : EXPOSE 3000
---> Running in 1cfe2e80d282
---> 5e3e740d5a9a
Removing intermediate container 1cfe2e80d282
Successfully built 5e3e740d5a9a
Volumes are runtime configurations in Docker. Because they are configurable, if you were to reference volumes during the build phase you would essentially be creating a potentially uncheckable broken dependency.
I'm sure there is a more technical reason - but it really shouldn't be done. Move all that stuff to the runtime setup command and you should be OK.

Resources