I'm running docker build and it's taking an awfully long time to run. Infact, it doesn't complete and I have to CTRL + C to quit.
Last night things were working fine. When I returned to the computer and tried to rebuild it started acting strange.
Here's my command:
docker build -t mywebsite/backend .
When I ran it I noticed this:
Sending build context to Docker daemon 213.8 MB
Step 1 : FROM ubuntu:14.04
I have no idea why the file size was 213.8. The only directory that is large is node_modules
and that contains .dockerignore
so it shouldn't be touching that directory.
After that ran I had an error, so I fixed it and reran:
docker build -t mywebsite/backend .
This time it just hung. And continues to do so.
Here is my Dockerfile
FROM ubuntu:14.04
# Set env. variables
ENV DEBIAN_FRONTEND noninteractive
# Application
ENV APP_PORT 3000
# Amazon
ENV AMAZON_BUCKET mybucket
ENV AMAZON_ACCESS_KEY_ID mykey
ENV AMAZON_SECRET_ACCESS_KEY mytoken
# Set working directory
WORKDIR ~/vms
# Install NodeJS
RUN apt-get update; apt-get install -y curl;
RUN curl -sL https://deb.nodesource.com/setup_4.x | sudo -E bash -
RUN apt-get install -y nodejs
# Install node dependencies
ADD package.json package.json
RUN npm install --production
# Copy files to the container
ADD src src
EXPOSE 3000
# Start application
RUN npm start
The directory I am in when I run the command is the one that contains the Dockerfile:
- backend
- node_modules
- src
- config
- routes
- views
index.js
Dockerfile
package.json
I'm running docker on Ubuntu 14.04
¶ If your Docker image builds takes a long time downloading dependencies, it's a good idea to check whether you're installing more than you need to. First, check if you might be downloading development dependencies which are not needed in your image at all.
Building Docker images is the longest process on this list. For example, it took 14 minutes to build each non-optimized backend image.
When you experience slow Docker performance, check your CPU, memory usage, and available disk space. Consider upgrading your system if a component does not perform as expected. When dealing with a specific container that is performing worse than expected, it may be helpful to check container-specific metrics.
Use Caching to Speed Up Builds You can also cache existing layers of Dockerfiles to be reused by Docker while rebuilding other images. This significantly improves build speeds and is more efficient.
I have no idea why the file size was 213.8. The only directory that is large is node_modules and that contains .dockerignore so it shouldn't be touching that directory.
That's not how .dockerignore
works. The .dockerignore
file should be in the same directory as your Dockerfile
and lists patterns to ignore. Create a file in backend
called .dockerignore
which simply contains the line node_modules
.
See here for more information: https://docs.docker.com/engine/reference/builder/#dockerignore-file
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With