Skip to content

Commit

Permalink
Separate LXD and Docker rst
Browse files Browse the repository at this point in the history
  • Loading branch information
rimelek committed Feb 21, 2021
1 parent 4f8f9ad commit a6d47d0
Show file tree
Hide file tree
Showing 3 changed files with 189 additions and 95 deletions.
3 changes: 2 additions & 1 deletion docs/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ Before you start working with the example projects, read :doc:`pages/intro/getti
:caption: Intro:

pages/intro/getting-started
pages/intro/container-basics
pages/intro/lxd
pages/intro/docker

.. toctree::
:maxdepth: 2
Expand Down
136 changes: 42 additions & 94 deletions docs/pages/intro/container-basics.rst → docs/pages/intro/docker.rst
Original file line number Diff line number Diff line change
@@ -1,85 +1,9 @@
.. _yq: https://github.com/mikefarah/yq

================
Container basics
================


LXD
===

Available remote servers to download base images.

https://images.linuxcontainers.org

.. code:: shell
lxc remote list
.. code:: shell
lxc image list images:ubuntu
# or
lxc image list images:ubuntu focal
# or
lxc image list images:ubuntu 20.04
# or
lxc image list ubuntu:20.04
List all aliases using one known alias

.. code:: shell
lxc image info ubuntu:x
It is a valid YAML so you can use `yq`_ to process it.

.. code:: shell
lxc image info ubuntu:focal | yq '.Aliases'
Start Ubuntu 20.04

.. code:: shell
lxc launch ubuntu:20.04 ubuntu-focal
List LXC containers

.. code:: shell
lxc list
Enter the container

.. code:: shell
lxc exec ubuntu-focal bash
Delete the container

.. code:: shell
lxc delete --force ubuntu-focal
You can even create a virtual machine instead of container if you have at least LXD 4.0 installed on your machine.

.. code:: shell
lxc launch --vm ubuntu:20.04 ubuntu-focal-vm
It will not work on all machines, only when Qemu KVM is supported on that machine. It also requires further configuration which is not part of this tutorial.

======
Docker
======

About the system
----------------
System information
==================

.. code:: bash
Expand All @@ -91,19 +15,20 @@ About the system
docker version --format '{{.Server.Version}}'
docker --version
Test a stateless DEMO application
---------------------------------
Run a stateless DEMO application
=================================

.. code:: bash
docker run --rm -p "8080:80" itsziget/phar-examples:1.0
# Press Ctrl-C to quit
Demo "hello-world" image
------------------------
Play with the "hello-world" container
=====================================

Start the container:
Start "hello-world" container
-----------------------------

.. code:: bash
Expand Down Expand Up @@ -136,12 +61,17 @@ Output:
For more examples and ideas, visit:
https://docs.docker.com/get-started/
List containers
---------------

List running containers

.. code:: bash
docker ps
# or
docker container ps
# or
docker container ls
# or
docker container list
Expand All @@ -151,6 +81,7 @@ List all containers
.. code:: bash
docker ps -a
# or use the other alias commands
List containers based on the hello-world image:

Expand All @@ -160,6 +91,9 @@ List containers based on the hello-world image:
# or
docker container list --all --filter ancestor=hello-world
Delete containers
-----------------

Delete a stopped container

.. code:: bash
Expand All @@ -180,7 +114,8 @@ If the generated name of the container is "angry_shaw"
docker rm -f angry_shaw
Start a container with a name:
Start a container with a name
-----------------------------

.. code:: bash
Expand Down Expand Up @@ -211,31 +146,37 @@ Delete the container named "hello"
docker rm hello
Start a container and delete it automatically when it stops.
Start a container and delete it automatically when it stops
-----------------------------------------------------------

.. code:: bash
docker run --rm hello-world
Apache HTTPD webszerver
-----------------------
Start Apache HTTPD webszerver
=============================

Start the container in the foreground. ("attached" mode)
--------------------------------------------------------

.. code:: bash
docker run --name web httpd:2.4
There will be no prompt until you press "CTRL+C" to stop the container running in the foreground.

Start it in the background as a daemon:
Start it in the background ("detached" mode)
--------------------------------------------

.. code:: bash
docker rm web
docker run -d --name web httpd:2.4
Now you can see the running container by executing "docker ps".
Now you can see the running container by executing :code:`docker ps`.

Check container logs
--------------------

Check the output of the container running in the background:

Expand All @@ -252,7 +193,10 @@ Watch the output (logs) continuously
docker logs -f web
# Press Ctrl-C to stop wathcing
Get the local IP address of the container:
Open the webpage using an IP address
------------------------------------

Get the IP address:

.. code:: bash
Expand All @@ -270,13 +214,18 @@ Output:

<html><body><h1>It works!</h1></body></html>

Use port forwarding
-------------------

Delete the container named "web" and forward the port 8080 from the host to the containers internal port 80:

.. code:: bash
docker rm -f web
docker run -d -p "8080:80" --name web httpd:2.4
Then you can access the page using host's IP address.

Work with the container's filesystem without building your own image
--------------------------------------------------------------------

Expand Down Expand Up @@ -311,10 +260,9 @@ Run a command inside a container:
It does not support Pseudo-TTY so some commands may not work.

Networks
--------
Get all of the IP addresses
---------------------------

.. code:: bash
docker inspect web --format "{{.NetworkSettings.IPAddress}}"
docker inspect web --format "{{range .NetworkSettings.Networks}}{{.IPAddress}} {{end}}"

0 comments on commit a6d47d0

Please sign in to comment.