started Docker for Mac

# 获取版本信息
$ docker version
$ docker info
# service 命令的用法
$ sudo service docker start
# systemctl 命令的用法
$ sudo systemctl start docker
$ docker image pull library/hello-world
$ docker image pull hello-world
$ docker image pull ubuntu
$ docker image ls -a
$ docker image rm ubuntu
$ docker container run ubuntu
$ docker container rm ubuntu
$ docker container kill ubuntu
$ docker container ls -a
$ docker container run -p 8000:3000 -it koa-demo:0.0.1 /bin/bash

https://docs.docker.com/docker-for-mac/

http://www.ruanyifeng.com/blog/2018/02/docker-tutorial.html

Welcome to Docker for Mac! Docker is a full development platform for creating containerized apps, and Docker for Mac is the best way to get started with Docker on a Mac.

See Install Docker for Mac for information on system requirements and stable & edge channels.

Check versions

Ensure your versions of dockerdocker-compose, and docker-machine are up-to-date and compatible with Docker.app. Your output may differ if you are running different versions.

$ docker --version
Docker version 18.09, build c97c6d6

$ docker-compose --version
docker-compose version 1.23.1, build 8dd22a9

$ docker-machine --version
docker-machine version 0.16.0, build 9ba6da9

Explore the application

  1. Open a command-line terminal and test that your installation works by running the simple Docker image, hello-world:
    $ docker run hello-world
    
    Unable to find image 'hello-world:latest' locally
    latest: Pulling from library/hello-world
    ca4f61b1923c: Pull complete
    Digest: sha256:ca0eeb6fb05351dfc8759c20733c91def84cb8007aa89a5bf606bc8b315b9fc7
    Status: Downloaded newer image for hello-world:latest
    
    Hello from Docker!
    This message shows that your installation appears to be working correctly.
    ...
    
  2. Start a Dockerized web server. Like the hello-world image above, if the image is not found locally, Docker pulls it from Docker Hub.
    $ docker run -d -p 80:80 --name webserver nginx
    
  3. In a web browser, go to http://localhost/ to view the nginx homepage. Because we specified the default HTTP port, it isn’t necessary to append :80 at the end of the URL.nginx home page

    Early beta releases used docker as the hostname to build the URL. Now, ports are exposed on the private IP addresses of the VM and forwarded to localhost with no other host name set.

  4. View the details on the container while your web server is running (withdocker container ls or docker ps):
    $ docker container ls
    CONTAINER ID   IMAGE   COMMAND                  CREATED              STATUS              PORTS                         NAMES
    56f433965490   nginx   "nginx -g 'daemon off"   About a minute ago   Up About a minute   0.0.0.0:80->80/tcp, 443/tcp   webserver
    
  5. Stop and remove containers and images with the following commands. Use the “all” flag (--all or -a) to view stopped containers.
    $ docker container ls
    $ docker container stop webserver
    $ docker container ls -a
    $ docker container rm webserver
    $ docker image ls
    $ docker image rm nginx

Leave a Comment