Q:

CMD dockerfile is not executed

I've create a docker image in order to seed my dockerized mongo instance:
FROM mongo:2.6
MAINTAINER Living Digital Way
COPY ./clients.init.json .
COPY ./users.init.json .

CMD mongoimport --host mongo --db lvdb --collection clients --type json --file ./clients.init.json --jsonArray --upsert --upsertFields client_id
CMD mongoimport --host mongo --db lvdb --collection users --type json --file ./users.init.json --jsonArray --upsert --upsertFields username

I first kick off my mongo instance:
docker run --name mongo -p 27017:27017 --hostname mongo mongo:2.6

After that, I perform my image:
docker run --link mongo:mongo registry.private.com/mongo_seed:demo

This is the output:
# docker run --name mongo-seed --link mongo:mongo registry.private.com/mongo-seed:demo
Unable to find image 'registry.private.com/mongo-seed:demo' locally
v1: Pulling from mongo-seed
046d0f015c61: Already exists
ba95eb02831f: Already exists
53dc8636c4de: Already exists
a1ba40c46d70: Already exists
58b7d37cc7a7: Already exists
6fc4041cef29: Already exists
4cb494f83a39: Already exists
29839a673e80: Pull complete
cc731752cc1a: Pull complete
Digest: sha256:9a88d141b426fb7e96d2418f63c1587f6c055602d77c13ddd4ef744d66d6acc2
Status: Downloaded newer image for registry.private.com/mongo-seed:demo
connected to: mongo
2016-09-09T12:11:42.194+0000 imported 1 objects  <<<<<<<<<<<<<<<<

As you can see only the last CMD is performed.
Am I doing something wrong?

A:

There can only be one CMD instruction in a Dockerfile. If you list more than one CMD then only the last CMD will take effect. I suggest you put the two commands in to a separate import.sh, copy it to your container and run it using CMD.
COPY ./clients.init.json .
COPY ./users.init.json .
COPY ./import.sh .
RUN ["chmod", "+x", "import.sh"] # -> only required, if import.sh is not executable

CMD ["import.sh"]

