CircleCI should use custom Dockerfile for primary container

Is it possible to get CircleCI to use a Dockerfile from my repository as the primary container?

Background: Looking at how to get CircleCI to setup my MySQL database from .sql.gz files for a Node project, it looks like I’ll have to run something akin to sudo apt-get install mysql-client every single time my container runs. This is obviously going to increase the time taken for every build, which is less than ideal.

The solution would be to write a Dockerfile & create/upload an image with this change written to it:

FROM circleci/node:8
RUN sudo apt-get update && sudo apt-get install mysql-client

Which is fine, except as the documentation instructs I would need to deploy this image somewhere, for example to Docker Hub or ECR. Would it not be better to follow a docker-compose-like syntax whereby CircleCI would build a Dockerfile of my choice, store it on a repository behind-the-scenes, use the md5 hash of the Dockerfile for image versions to help cache these builds, etc?

      - dockerfile: ./.circleci/Dockerfile
      - image: mysql:5.7
      - checkout
      - run: cat ./.circleci/tables.sql | mysql -u root -p mydb
      - run: gunzip < ./.circleci/sample-data.sql.gz | mysql -u root -p mydb
      - run: npm install
      - run: npm test
  - 'No container found: someimportantcompany/awesome-project:hashhashhash'
  - 'Building container: someimportantcompany/awesome-project:hashhashhash'
  - 'Configuring container: someimportantcompany/awesome-project:hashhashhash'

Until then, I’m going to be pushing my custom Docker container to Docker-Hub, but to do this for every project would be a serious pain!

1 Like

For complex build installations, I generally regard it as a better to create a separate project to build your build server. The main reason for this is that if you are careful with the size of the container you create, it will usually be faster to pull it than it will be to build it from scratch.

If you are concerned about the cost of a Docker registry, consider getting a free GitLab account. Each private project can store 10G of data for free, including Docker images.

That all said, if you are only installing a MySQL client, I would just suggest installing that every time. It is very normal on hosted CI to start with a blank container every time, and I expect that installation must be all of 15 seconds! :smile:

I believe a local CircleCI registry has already been suggested as a feature request.

1 Like

I mean, yes I think this is a fair solution. An additional 15s on a build that takes 1m isn’t going to affect much. I just figured it was a waste to have to install a client every… single… build!

If that’s considered “best” then :+1:

While not yet a common request, we have a feature request for that here:

Please vote to show support receive updates and add any comments you have to clarify how you would like this feature to work.

1 Like

This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.