Sign up
Login
New
Trending
Archive
English
English
Sign up
Login
New Paste
Add Image
Program – 1 Build a Docker Container from a Custom Dockerfile Project Structure Program-1/ ├── Dockerfile ├── app.py └── requirements.txt Step 1: Create Project Directory Command: mkdir Program-1 cd Program-1 Step 2: Create Dockerfile Command: nano Dockerfile Content of Dockerfile: # This is a Dockerfile # Dockerfile is a set of instructions that Docker # uses to build a container image # Use a slim Python base image FROM python:3.9-slim # Set the working directory inside the container WORKDIR /app # Copy the requirements file and install dependencies COPY requirements.txt . RUN pip install --no-cache-dir -r requirements.txt # Copy the application code COPY . . # Set Flask environment variables ENV FLASK_APP=app.py ENV FLASK_RUN_HOST=0.0.0.0 ENV FLASK_RUN_PORT=5000 # Expose the port the Flask app will run on EXPOSE 5000 # Define the command to run the Flask application CMD ["flask", "run"] Step 3: Create Python Application File Command: nano app.py Content of app.py: from flask import Flask app = Flask(__name__) @app.route("/") def hello(): return "Hello, Docker!" if __name__ == "__main__": app.run(host="0.0.0.0", port=5000) Step 4: Create Requirements File Command: nano requirements.txt Content of requirements.txt: flask Step 5: Build Docker Image Command: docker build -t program-1 . Step 6: Verify Docker Image Command: docker images Step 7: Run Docker Container Command: docker run -d -p 5000:5000 --name flask-container program-1 Step 8: Verify Running Container Command: docker ps Step 9: Test the Application Open a web browser and enter: http://localhost:5000 Output: Hello, Docker! Step 10: Stop the Docker Container Command: docker container stop flask-container Step 11: Remove the Docker Container Command: docker container rm flask-container Step 12: Remove Docker Image Command: docker image rm program-1
Settings
Title :
[Optional]
Paste Folder :
[Optional]
Select
Syntax :
[Optional]
Select
Markup
CSS
JavaScript
Bash
C
C#
C++
Java
JSON
Lua
Plaintext
C-like
ABAP
ActionScript
Ada
Apache Configuration
APL
AppleScript
Arduino
ARFF
AsciiDoc
6502 Assembly
ASP.NET (C#)
AutoHotKey
AutoIt
Basic
Batch
Bison
Brainfuck
Bro
CoffeeScript
Clojure
Crystal
Content-Security-Policy
CSS Extras
D
Dart
Diff
Django/Jinja2
Docker
Eiffel
Elixir
Elm
ERB
Erlang
F#
Flow
Fortran
GEDCOM
Gherkin
Git
GLSL
GameMaker Language
Go
GraphQL
Groovy
Haml
Handlebars
Haskell
Haxe
HTTP
HTTP Public-Key-Pins
HTTP Strict-Transport-Security
IchigoJam
Icon
Inform 7
INI
IO
J
Jolie
Julia
Keyman
Kotlin
LaTeX
Less
Liquid
Lisp
LiveScript
LOLCODE
Makefile
Markdown
Markup templating
MATLAB
MEL
Mizar
Monkey
N4JS
NASM
nginx
Nim
Nix
NSIS
Objective-C
OCaml
OpenCL
Oz
PARI/GP
Parser
Pascal
Perl
PHP
PHP Extras
PL/SQL
PowerShell
Processing
Prolog
.properties
Protocol Buffers
Pug
Puppet
Pure
Python
Q (kdb+ database)
Qore
R
React JSX
React TSX
Ren'py
Reason
reST (reStructuredText)
Rip
Roboconf
Ruby
Rust
SAS
Sass (Sass)
Sass (Scss)
Scala
Scheme
Smalltalk
Smarty
SQL
Soy (Closure Template)
Stylus
Swift
TAP
Tcl
Textile
Template Toolkit 2
Twig
TypeScript
VB.Net
Velocity
Verilog
VHDL
vim
Visual Basic
WebAssembly
Wiki markup
Xeora
Xojo (REALbasic)
XQuery
YAML
HTML
Expiration :
[Optional]
Never
Self Destroy
10 Minutes
1 Hour
1 Day
1 Week
2 Weeks
1 Month
6 Months
1 Year
Status :
[Optional]
Public
Unlisted
Private (members only)
Password :
[Optional]
Description:
[Optional]
Tags:
[Optional]
Encrypt Paste
(
?
)
Create Paste
You are currently not logged in, this means you can not edit or delete anything you paste.
Sign Up
or
Login
Site Languages
×
English