Junior — Middle
What steps are needed to create a Docker image using a Dockerfile?
sobes.tech AI
Answer from AI
To create a Docker image using a Dockerfile, follow these steps:
- Create a Dockerfile — a text file with instructions for building the image.
- Specify the base image using the
FROMinstruction, for example:FROM php:8.0-apache - Add necessary commands to install dependencies, copy files, configure the environment, for example:
COPY . /var/www/html/ RUN docker-php-ext-install pdo pdo_mysql - Define the command to run the container using
CMDorENTRYPOINT. - Build the image with the command in the terminal:
docker build -t my-php-app . - Run the container based on the created image:
docker run -d -p 8080:80 my-php-app
Thus, the Dockerfile describes how to build the image, and the docker build command performs the build.