All Episodes

40: Rust in Production with Docker

From local webapp Rocket with Rust last week, to getting the whole thing into production. If there's one thing I've learned over the last year, it's that any evaluation/project/proto-type/mockup/thing is best examined by taking it from localhost all the way to **PROD** before making any rash decisions. I'm not going to lie, this was really difficult to accomplish.

Rust from local to prod

  • Get Docker installed

    • Sounds simple right?
    • WSL install. Windows damon, linux subsystem
    • doesn’t actually need a VM!
  • If you get an error the next time you start your WSL terminal don’t freak out. It’s a bug with 18.03 and you can easily fix it. Hit CTRL+Shift+ECS to open task manager, goto the “Services” tab, find the “LxssManager” service and restart it.

    • Well that is quite a ride, isn’t it. we haven’t even started up a container yet!
  • Get Rocket Running in Docker locally

    • Gonna need a dockerfile
    • Need to make sure the DNS for pulling docker image is set ?
    • I remember sysAdmin, it’s like trying a 1,000 keys, and it’s always the 889th key that works
    docker build -t friendlyhello .  # Create image using this directory's Dockerfile
    docker run -p 4000:80 friendlyhello  # Run "friendlyname" mapping port 4000 to 80
    docker run -d -p 4000:80 friendlyhello         # Same thing, but in detached mode
    docker container ls                                # List all running containers
    docker container ls -a             # List all containers, even those not running
    docker container stop            # Gracefully stop the specified container
    docker container kill          # Force shutdown of the specified container
    docker container rm         # Remove specified container from this machine
    docker container rm $(docker container ls -a -q)         # Remove all containers
    docker image ls -a                             # List all images on this machine
    docker image rm             # Remove specified image from this machine
    docker image rm $(docker image ls -a -q)   # Remove all images from this machine
    docker login             # Log in this CLI session using your Docker credentials
    docker tag  username/repository:tag  # Tag  for upload to registry
    docker push username/repository:tag            # Upload tagged image to registry
    docker run username/repository:tag                   # Run image from a registry
    • So this might take a bit
  • Get Container running somewhere else?

    • New Tactic, since it appears to be running, but I can’t hit it from the outside

    • docker run hello-world —> cool that works fine. ugh

    • To generate this message, Docker took the following steps:

      1. The Docker client contacted the Docker daemon.
      2. The Docker daemon pulled the “hello-world” image from the Docker Hub. (amd64)
      3. The Docker daemon created a new container from that image which runs the executable that produces the output you are currently reading.
      4. The Docker daemon streamed that output to the Docker client, which sent it to your terminal.
    • Cheat Sheet

    • ## List Docker CLI commands
      docker
      docker container --help
      
      ## Display Docker version and info
      docker --version
      docker version
      docker info
      
      ## Execute Docker image
      docker run hello-world
      
      ## List Docker images
      docker image ls
      
      ## List Docker containers (running, all, all in quiet mode)
      docker container ls
      docker container ls --all
      docker container ls -aq
  • Winning hand

  • docker build -t hello-rocket .

  • docker run --rm -p 8080:8080 -it --name running-rocket hello-rocket

  • FROM rustlang/rust:nightly
    # Set the working directory to /app
    WORKDIR /app
    
    # Copy the current directory contents into the container at /app
    COPY . .
    
    EXPOSE 8080
    RUN rustc --version && cargo build
    # CMD [ "cargo", "run" ]
    # CMD cargo run 
    
    CMD ROCKET_ENV=development cargo run

    There it is. the willing combination!!!!!!!

  • So, does a compiled language need to be in a container

    • maybe? not really i guess
    • I was hoping to put it, and postgress in a separate containers
    • yes, volume persistent, or better still, RDS AWS.
  • The Promise NO VM’s

    • and cli push deploy, right ?
  • CHECK IT OUT IN PROD

Picks

Resources

Follow

  • JavaScript to Elm

    • Email:
  • Jesse Tomchak

Published 14 Jun 2018

A show about learning Elm, Functional Programing, and generally leveling up as a JS developer.