Why docker is not found? I want to deploy a Next.js app to AWS ECS.
λ (Server) server-side renders at runtime (uses getInitialProps or getServerSideProps)
○ (Static) automatically rendered as static HTML (uses no initial props)
● (SSG) automatically generated as static HTML + JSON (uses getStaticProps)
$ echo "Building the Docker image..."
Building the Docker image...
$ docker build -t $IMAGE_TAG .
/bin/sh: eval: line 163: docker: not found
Cleaning up project directory and file based variables
00:00
ERROR: Job failed: exit code 127
gitlab-ci.yml
image: docker:20.10.7 # Use a specific Docker image
services:
- docker:20.10.7-dind # Docker-in-Docker service
stages:
- build
- test
- deploy
variables:
DOCKER_IMAGE: 'tikex-repository'
AWS_DEFAULT_REGION: eu-central-1
AWS_ECR_REGISTRY: 767397666295.dkr.ecr.eu-central-1.amazonaws.com
AWS_ECR_REPOSITORY: tikex-repository
ECS_CLUSTER: tikex-cluster
ECS_SERVICE: tikex-service
ECS_TASK_DEFINITION: my-task-def
before_script:
- docker --version
- docker info
- aws configure set aws_access_key_id $AWS_ACCESS_KEY_ID
- aws configure set aws_secret_access_key $AWS_SECRET_ACCESS_KEY
- aws configure set default.region $AWS_DEFAULT_REGION
build:
stage: build
image: docker:latest
services:
- docker:dind
script:
- docker version # Verify Docker is installed and running
- docker info
- docker build -t $DOCKER_IMAGE:$CI_COMMIT_SHA .
- docker tag $DOCKER_IMAGE:$CI_COMMIT_SHA $AWS_ECR_REGISTRY/$AWS_ECR_REPOSITORY:$CI_COMMIT_SHA
- docker push $AWS_ECR_REGISTRY/$AWS_ECR_REPOSITORY:$CI_COMMIT_SHA
test:
stage: test
image: node:latest
services:
- docker:dind
script:
- npm install
- npm run test
deploy:
stage: deploy
image: amazon/aws-cli
script:
- aws ecs update-service --cluster $ECS_CLUSTER --service $ECS_SERVICE --task-definition $ECS_TASK_DEFINITION --force-new-deployment
Dockerfile:
# Use an official Node.js runtime as a parent image
FROM node:18-alpine
# Set the working directory in the container
WORKDIR /app
# Copy package.json and package-lock.json
COPY package*.json ./
# Install dependencies
RUN npm install
# Copy the rest of the application code
COPY . .
# Build the Next.js application
ARG NEXT_PUBLIC_BASE_URL=""
RUN npm run build
# Expose the port the app runs on
EXPOSE 3000
# Start the Next.js application
CMD ["npm", "start"]