A unique feature to CircleCI is the ability to run a job in any Docker image. CircleCI provides a number of pre-built Docker images tailored to specific programming languages or CI/CD needs.
You can specify using a Docker image as part of any CircleCI job. The syntax is as follows:
The above example uses the pre-built Node image, which provides access to Node.js and a number of commonly used helper tools. Additional tools can also be installed as part of the job's steps, if needed.
For a complete CircleCI workflow, demonstrating both a Docker and machine job executor, copy the following into your config.yml file:
# Use the latest 2.1 version of CircleCI pipeline process engine.
# See: https://circleci.com/docs/2.0/configuration-reference
version: 2.1
# Define a job to be invoked later in a workflow.
# See: https://circleci.com/docs/2.0/configuration-reference/#jobs
jobs:
say-hello-docker:
# Uses a Docker image to run the job in.
# There are a number of useful Docker images for different programming languages.
# You can specify an image from Dockerhub or use one of the Convenience Images from CircleCI's Developer Hub.
# See: https://circleci.com/docs/2.0/executor-types/#using-docker
docker:
- image: cimg/node:18.0.0
# Add steps to the job
# See: https://circleci.com/docs/2.0/configuration-reference/#steps
steps:
- checkout
- run:
name: "Say Hello From Docker"
command: "echo Hello from docker!"
- run: node --version
say-hello-machine:
# Uses a Linux machine instead of a Docker image. You still have to specify which version of Ubuntu to use.
# This is Ubuntu 20.04, latest patch. A specific patch version can be specified instead, if desired.
machine:
image: ubuntu-2004:current
# This determines the amount of virtual CPU and RAM the job has. A larger or smaller size might be used, if needed.
# See: https://circleci.com/docs/2.0/executor-types/#using-machine
resource_class: medium
steps:
- checkout
- run:
name: "Say Hello From Machine"
command: "echo Hello from machine!"
# Invoke jobs via workflows
# See: https://circleci.com/docs/2.0/configuration-reference/#workflows
workflows:
say-hello-workflow:
jobs:
- say-hello-docker
- say-hello-machine
A unique feature to CircleCI is the ability to run a job in any Docker image. CircleCI provides a number of pre-built Docker images tailored to specific programming languages or CI/CD needs.
You can specify using a Docker image as part of any CircleCI job. The syntax is as follows:
The above example uses the pre-built Node image, which provides access to Node.js and a number of commonly used helper tools. Additional tools can also be installed as part of the job's steps, if needed.
For a complete CircleCI workflow, demonstrating both a Docker and machine job executor, copy the following into your
config.yml
file:For further information, see https://circleci.com/docs/2.0/executor-types/#using-docker.