Code Chewing Guides

PAGE 1 OF 4
  • How to create a new branch in Git

    This quick guide assumes creating a new git branch from the command line.

    For example, you've made some changes to an existing branch, but have decided these code changes would be better off in a new branch. Assuming that you haven't yet committed these changes in the current branch, you can effectively switch these changes into a new branch, with the following Git command:

    $ git checkout -b branch_name
    

    Executing git status will reveal your new branch destination. From here, you'll probably want to commit and push the new branch up to the remote repository!

    Farewell

    Read more
  • How to run a command from history - Linux

    Sometimes !! to execute the last command (albeit brilliantly convenient), isn't what you want. Instead, this is how to list all your recent history commands and cherry picking the command you want to execute again:

    $ history
      369  git pull origin master
      370  sudo docker-compose build
      371  sudo docker-compose stop
      372  sudo docker-compose up -d
      373  sudo docker-compose ps
      374  sudo docker-compose stop
      375  sudo docker-compose up -d
      376  exit
    

    Suppose I want to run the command located at 370 again:

    $ !370
      sudo docker-compose build
      ...
    

    ! followed by the number in history. Easy.

    Read more
  • Horizontal scroll fix for pre HTML with Bootstrap CSS

    When using Bootstrap CSS and <pre>/<code> blocks for sample code, I disappointingly discovered the the code block wasn't horizontally scrolling, and I ended up with a big mess of wrapped code for smaller screen sizes.

    For example, you might have some wide spanning HTML like the following snippet:

    <pre><code>$ docker-compose ps
       Name                Command                State                    Ports                   
    ----------------------------------------------------------------------------------------------------------
    app_mysql_1   docker-entrypoint.sh mysqld      Up      3306/tcp                                 
    app_site_1    docker-php-entrypoint apac ...   Up      0.0.0.0:443->443/tcp, 0.0.0.0:80->80/tcp 
    ...</code></pre>
    

    And it rendered like this:

    pre html wrap fix - bootstrap css

    Read more
  • Privately expose a service / container port with docker compose

    When using docker compose, there are multiple ways to expose / publish a service / container port so that another container can access the service. Depending on the service, you might only want the published port to remain inside the private docker network, and not exposed to the internet.

    For example, perhaps you've got a MySQL database running inside a container - you probably don't want to expose the default port (3306) to the world wide web, right? But, you do want to expose it to the other containers within the docker network. On the flip side of this, your web application running the website will rightly want to expose itself to the www.

    Setting up the public container

    Let's suppose you've already got your Dockerfile in place for your public container build... be it some kind of web application... it doesn't really matter. Your docker compose file (docker-compose.yml) would look something like this:

    version: '2'
    
    networks:
      privatenetwork:
    
    services:
      site:
        build: .
        ports:
          - "80:80"
          - "443:443"
        networks:
          - privatenetwork
    
    Read more
  • How to run a command inside a docker container

    If you've built and launched a docker image, you might be left wondering what's actually going on within the container? What does the file system look like? Does that package exist?

    Perhaps you want to check some configuration setting, or check to see if a module or particular service is enabled and running... well there's a way.

    Get the docker container id

    If you don't know the docker image name or container id, begin by listing the running docker containers:

    $ docker ps
    CONTAINER ID  IMAGE         COMMAND         CREATED         STATUS         PORTS                         NAMES
    7015544736d9  fa21f0188248  "docker-ph..."  11 seconds ago  Up 10 seconds  80/tcp, 0.0.0.0:443->443/tcp  codechewing
    
    Read more
Code Chewing Twitter