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?
jobs:
build:
docker:
- dockerfile: ./.circleci/Dockerfile
- image: mysql:5.7
steps:
- 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
Results:
- '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!