How to create a Mongo Docker Image with default collections and data?

The problem was that information could not be saved on /db/data, so I’ve created a solution creating my own data directory. # Parent Dockerfile https://github.com/docker-library/mongo/blob/982328582c74dd2f0a9c8c77b84006f291f974c3/3.0/Dockerfile FROM mongo:latest # Modify child mongo to use /data/db2 as dbpath (because /data/db wont persist the build) RUN mkdir -p /data/db2 \ && echo “dbpath = /data/db2” > /etc/mongodb.conf \ … Read more

Docker container doesn’t expose ports when –net=host is mentioned in the docker run command

I was confused by this answer. Apparently my docker image should be reachable on port 8080. But it wasn’t. Then I read https://docs.docker.com/network/host/ To quote The host networking driver only works on Linux hosts, and is not supported on Docker for Mac, Docker for Windows, or Docker EE for Windows Server. That’s rather annoying as … Read more

How to cache the RUN npm install instruction when docker build a Dockerfile

Ok so I found this great article about efficiency when writing a docker file. This is an example of a bad docker file adding the application code before running the RUN npm install instruction: FROM ubuntu RUN echo “deb http://archive.ubuntu.com/ubuntu precise main universe” > /etc/apt/sources.list RUN apt-get update RUN apt-get -y install python-software-properties git build-essential … Read more

How to name Dockerfiles

[Please read the full answer]Don’t change the name of the dockerfile if you want to use the autobuilder at hub.docker.com. Don’t use an extension for docker files, leave it null. File name should just be: (no extension at all) Dockerfile However, now you can name dockerfiles like, test1.Dockerfile $ docker build -f dockerfiles/test1.Dockerfile -t test1_app … Read more

Multiple commands on docker ENTRYPOINT

In case you want to run many commands at entrypoint, the best idea is to create a bash file. For example commands.sh like this #!/bin/bash mkdir /root/.ssh echo “Something” cd tmp ls … And then, in your DockerFile, set entrypoint to commands.sh file (that execute and run all your commands inside) COPY commands.sh /scripts/commands.sh RUN … Read more

Use docker run command to pass arguments to CMD in Dockerfile

Make sure your Dockerfile declares an environment variable with ENV: ENV environment default_env_value ENV cluster default_cluster_value The ENV <key> <value> form can be replaced inline. Then you can pass an environment variable with docker run. Note that each variable requires a specific -e flag to run. docker run -p 9000:9000 -e environment=dev -e cluster=0 -d … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)