Loading...
Loading...
Build and run a local production Docker image for a Next.js app safely. Use this skill when the user wants to build a Docker image, run a container with an env file, check whether an image version already exists locally, or deploy a Next.js app locally with Docker without hard-coding the project name.
npx skill4agent add codingthailand/my-agent-skill-nt deploy-docker-productionPROJECT_NAME=<resolved project name>
IMAGE_NAME=<resolved image name>
IMAGE_VERSION=<resolved version>
IMAGE_TAG=${IMAGE_NAME}:${IMAGE_VERSION}
CONTAINER_NAME=<resolved container name>
ENV_FILE=<resolved env file>
HOST_PORT=<resolved host port>
CONTAINER_PORT=<resolved container port>package.jsonnamepackage.jsonname1.0.0.env.productionHOST_PORT=4000CONTAINER_PORT=3000package.json name: nextjs-skill-app-workshop
PROJECT_NAME=nextjs-skill-app-workshop
IMAGE_NAME=nextjs-skill-app-workshop
IMAGE_VERSION=1.0.0
IMAGE_TAG=nextjs-skill-app-workshop:1.0.0
CONTAINER_NAME=nextjs-skill-app-workshop
ENV_FILE=.env.production
HOST_PORT=4000
CONTAINER_PORT=3000Dockerfilelatestdocker system prunedocker image prunedocker volume prunepwd
ls -la
test -f package.json && echo "OK: package.json found" || echo "WARN: package.json not found"
test -f Dockerfile && echo "OK: Dockerfile found" || echo "ERROR: Dockerfile not found"
test -f "$ENV_FILE" && echo "OK: env file found: $ENV_FILE" || echo "ERROR: env file not found: $ENV_FILE"
docker --version
docker info >/dev/null && echo "OK: Docker daemon is running" || echo "ERROR: Docker daemon is not running"Dockerfilepackage.jsonnode -p "require('./package.json').name"package.jsonnamebasename "$PWD"My Next App -> my-next-app
nextjs_skill_app -> nextjs-skill-appdocker image inspect "$IMAGE_TAG" >/dev/null 2>&1 \
&& echo "EXISTS: $IMAGE_TAG" \
|| echo "AVAILABLE: $IMAGE_TAG"docker images "$IMAGE_NAME" --format "table {{.Repository}}\t{{.Tag}}\t{{.ID}}\t{{.CreatedSince}}\t{{.Size}}"docker build1.0.1docker ps -a --filter "name=^/${CONTAINER_NAME}$" \
--format "table {{.Names}}\t{{.Image}}\t{{.Status}}\t{{.Ports}}"docker build -t "$IMAGE_TAG" .docker image inspect "$IMAGE_TAG" >/dev/null \
&& echo "OK: image built successfully: $IMAGE_TAG" \
|| echo "ERROR: image not found after build: $IMAGE_TAG"docker run --restart=always -d \
--name "$CONTAINER_NAME" \
--env-file "$ENV_FILE" \
-p "${HOST_PORT}:${CONTAINER_PORT}" \
"$IMAGE_TAG"docker ps --filter "name=^/${CONTAINER_NAME}$" \
--format "table {{.Names}}\t{{.Image}}\t{{.Status}}\t{{.Ports}}"
docker logs --tail=80 "$CONTAINER_NAME"
curl -I "http://localhost:${HOST_PORT}"Up${HOST_PORT}->${CONTAINER_PORT}curl -I200301302307308curlImage tag already exists locally:
<IMAGE_TAG>
Recommended action:
- Use a new patch version, such as 1.0.1
- Or explicitly confirm rebuilding the same tagContainer already exists:
<CONTAINER_NAME>
Please confirm whether to stop/remove it, or provide a different container name.lsof -i :"$HOST_PORT"HOST_PORTEnv file was not found:
<ENV_FILE>
I cannot run the container with --env-file until this file exists.Docker is installed but the daemon is not running.
Start Docker Desktop or Docker Engine, then run the preflight checks again.Result:
- Project: <PROJECT_NAME>
- Image: <IMAGE_TAG>
- Container: <CONTAINER_NAME>
- Env file: <ENV_FILE>
- Port: http://localhost:<HOST_PORT>
- Restart policy: always
- Validation: passed/failed
Commands used:
<list important commands>
Notes:
<any warnings, existing image/container conflicts, or follow-up action>