Hier sind 10 Übungen zu Docker mit je 2 Lösungen:
Lösung 1:
# Dockerfile
FROM nginx:latest COPY index.html /usr/share/nginx/html
Lösung 2:
docker run -d -p 8080:80 --name webserver -v /path/to/html:/usr/share/nginx/html nginx:latest
Lösung 1:
# Dockerfile FROM mysql:latest ENV MYSQL_ROOT_PASSWORD=my-secret-pw ENV MYSQL_DATABASE=my-db ENV MYSQL_USER=my-user ENV MYSQL_PASSWORD=my-password schema.sql /docker-entrypoint-initdb.d/
Lösung 2:
docker run -d -p 3306:3306 --name mysql -e MYSQL_ROOT_PASSWORD=my-secret-pw -e MYSQL_DATABASE=my-db -e MYSQL_USER=my-user -e MYSQL_PASSWORD=my-password mysql:latest
Lösung 1:
# Dockerfile FROM node:latest WORKDIR /app COPY package*.json ./ RUN npm install COPY . . EXPOSE 3000 CMD [ "npm", "start" ]
Lösung 2:
docker run -d -p 3000:3000 --name node-app -v /path/to/app:/app -w /app node:latest npm start
Lösung 1:
# Dockerfile FROM python:latest WORKDIR /app COPY requirements.txt . RUN pip install --no-cache-dir -r requirements.txt COPY . . CMD [ "python", "app.py" ]
Lösung 2:
docker run -d -p 5000:5000 --name python-app -v /path/to/app:/app -w /app python:latest python app.py
Lösung :e# Dockerfile FROM redis:latest CMD ["redis-server"]
Lösung 2:
docker run -d -p 6379:6379 --name redis redis:latest
Lösung 1:
# Dockerfile FROM mongo:latest EXPOSE 27017 CMD ["mongod"]
Lösung 2:
docker run -d -p 27017:27017 --name mongodb mongo:latest
Lösung 1:
# Dockerfile FROM postgres:latest ENV POSTGRES_PASSWORD=mysecretpassword ENV POSTGRES_DB=mydb EXPOSE 5432 COPY init.sql /docker-entrypoint-initdb.d/
Lösung 2:
docker run -d -p 5432:5432 --name postgres -e POSTGRES_PASSWORD=mysecretpassword -e POSTGRES_DB=mydb -v /path/to/sql:/docker-entrypoint