Difference between revisions of "Docker"

From neil.tappsville.com
Jump to navigationJump to search
m
Line 7: Line 7:
 
  docker ps -a
 
  docker ps -a
 
Run a container
 
Run a container
  docker run [image]
+
  docker run [image] [command]
 
  -d detached
 
  -d detached
 
  -i interactive
 
  -i interactive
Line 33: Line 33:
 
==Dockerfile==
 
==Dockerfile==
 
Contains Instructions or Arguments
 
Contains Instructions or Arguments
 +
 +
CMD can be as per cli or in json format
 +
<pre>
 +
CMD command param1
 +
CMD ["command","param1"]
 +
</pre>
 
<pre>FROM ubuntu:18.04
 
<pre>FROM ubuntu:18.04
 
COPY . /app
 
COPY . /app
Line 44: Line 50:
 
  docker build [path/Dockerfilefolder]
 
  docker build [path/Dockerfilefolder]
 
  -t name:tag
 
  -t name:tag
 +
 +
Create a Ubuntu container that sleeps for 5 seconds before exiting
 +
Dockerfile
 +
From Ubuntu
 +
CMD sleep 5
 +
 +
docker build -t ubuntu-sleeper .
 +
docker run ubuntu-sleeper
 +
 +
Dockerfile
 +
From Ubuntu
 +
ENTRYPOINT ["sleep"]
 +
CMD ["5"]            (becomes the default)
 +
 +
docker build -t ubuntu-sleeper .
 +
docker run ubuntu-sleeper 10

Revision as of 04:11, 23 August 2020

Docker

Containers

List running containers

docker ps

List all containers

docker ps -a

Run a container

docker run [image] [command]
-d detached
-i interactive
-t terminal  (usually -it)
-e VAR=value  (environment variables)
--name name
run:version (using a tag)


Port mapping

-p (host/external):(container/internal)

Directory mapping

-v /host/dir:/container/dir

Inspect (returns json)

docker inspect [container]

Images

List images

docker image ls

Remove image (must have no containers attached)

docker rmi [image]

Dockerfile

Contains Instructions or Arguments

CMD can be as per cli or in json format

CMD command param1
CMD ["command","param1"]
FROM ubuntu:18.04
COPY . /app
ADD root/bashrc /root/.bashrc
ENV HOME /root
WORKDIR /root
RUN make /app
CMD python /app/app.py

Build

docker build [path/Dockerfilefolder]
-t name:tag

Create a Ubuntu container that sleeps for 5 seconds before exiting Dockerfile

From Ubuntu
CMD sleep 5
docker build -t ubuntu-sleeper .
docker run ubuntu-sleeper

Dockerfile

From Ubuntu
ENTRYPOINT ["sleep"]
CMD ["5"]             (becomes the default)
docker build -t ubuntu-sleeper .
docker run ubuntu-sleeper 10